Skip to content

Commit 0b7a69c

Browse files
authored
[FIX] specification_condition update (#644)
* fix specification_condition update * style issues
1 parent 1741586 commit 0b7a69c

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

compose/neurosynth_compose/models/analysis.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class SpecificationCondition(BaseMixin, db.Model):
4949
)
5050
condition = relationship("Condition", backref=backref("specification_conditions"))
5151
specification = relationship(
52-
"Specification", backref=backref("specification_conditions")
52+
"Specification",
53+
backref=backref("specification_conditions", cascade="all, delete-orphan"),
5354
)
5455
user_id = db.Column(db.Text, db.ForeignKey("users.external_id"))
5556
user = relationship("User", backref=backref("specification_conditions"))

compose/neurosynth_compose/resources/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def update_or_create(cls, data, id=None, commit=True):
190190
if cls._attribute_name:
191191
existing_nested = getattr(record, cls._attribute_name, None)
192192

193-
if existing_nested and len(existing_nested) == len(rec_data):
193+
if existing_nested:
194194
_ = [
195195
rd.update({"id": ns.id})
196196
for rd, ns in zip(

compose/neurosynth_compose/tests/api/test_specification.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,59 @@ def test_update_condition_weight(session, app, auth_client, user_data):
112112
assert set(get_spec.json[key]) == set(value)
113113
else:
114114
assert get_spec.json[key] == value
115+
116+
117+
def test_other_specification_conditions(session, app, auth_client, user_data):
118+
specification_data = {
119+
"conditions": [True, False],
120+
"corrector": None,
121+
"database_studyset": None,
122+
"estimator": {
123+
"args": {
124+
"**kwargs": {},
125+
"kernel__fwhm": None,
126+
"kernel__sample_size": None,
127+
"n_iters": 10000,
128+
},
129+
"type": "ALESubtraction",
130+
},
131+
"filter": "included",
132+
"type": "CBMA",
133+
"weights": [1, -1],
134+
}
135+
136+
create_spec = auth_client.post("/api/specifications", data=specification_data)
137+
138+
updated_data = {
139+
"type": "CBMA",
140+
"estimator": {
141+
"type": "ALESubtraction",
142+
"args": {
143+
"**kwargs": {},
144+
"kernel__fwhm": None,
145+
"kernel__sample_size": None,
146+
"n_iters": 10000,
147+
},
148+
},
149+
"corrector": None,
150+
"filter": "included",
151+
"conditions": [True],
152+
"database_studyset": "neuroquery",
153+
"weights": [1],
154+
}
155+
156+
assert create_spec.status_code == 200
157+
158+
spec_id = create_spec.json["id"]
159+
160+
update_spec = auth_client.put(f"/api/specifications/{spec_id}", data=updated_data)
161+
assert update_spec.status_code == 200
162+
163+
get_spec = auth_client.get(f"/api/specifications/{spec_id}")
164+
assert get_spec.status_code == 200
165+
166+
for key, value in updated_data.items():
167+
if isinstance(value, list):
168+
assert set(get_spec.json[key]) == set(value)
169+
else:
170+
assert get_spec.json[key] == value

0 commit comments

Comments
 (0)