Skip to content

Commit 1333ae2

Browse files
authored
fix deactivation schema (#1100)
1 parent b829a3a commit 1333ae2

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

store/backend/neurostore/schemas/data.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class PointSchema(BaseDataSchema):
216216
entities = fields.Nested(EntitySchema, many=True, load_only=True)
217217
cluster_size = fields.Float(allow_none=True)
218218
subpeak = fields.Boolean(allow_none=True)
219-
deactivation = fields.Boolean()
219+
deactivation = fields.Boolean(missing=False, allow_none=True)
220220
order = fields.Integer()
221221
coordinates = fields.List(fields.Float(), dump_only=True)
222222

@@ -246,6 +246,11 @@ def process_values(self, data, **kwargs):
246246
data["order"] = 1 if max_order is None else max_order + 1
247247
else:
248248
data["order"] = 1
249+
250+
# Convert deactivation None to False
251+
if data.get("deactivation") is None:
252+
data["deactivation"] = False
253+
249254
return data
250255

251256
@pre_dump

store/backend/neurostore/tests/test_schemas.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from ..schemas import StudySchema, StudysetSchema, StudysetSnapshot
3+
from ..schemas import StudySchema, StudysetSchema, StudysetSnapshot, PointSchema
44
from ..models import Study, Studyset
55
from neurostore.schemas.pipeline import (
66
PipelineSchema,
@@ -109,3 +109,28 @@ def test_PipelineStudyResultSchema():
109109
assert result["result_data"] == {"result": "success"}
110110
assert result["file_inputs"] == {"input1": "file1"}
111111
assert result["status"] == "UNKNOWN"
112+
113+
114+
def test_PointSchema_deactivation_field():
115+
"""Test deactivation field behavior in PointSchema"""
116+
schema = PointSchema()
117+
118+
# Test 1: When deactivation is explicitly set to None, it should convert to False
119+
data_with_none = {"x": 1.0, "y": 2.0, "z": 3.0, "deactivation": None}
120+
result = schema.load(data_with_none)
121+
assert result["deactivation"] is False
122+
123+
# Test 2: When deactivation is not included in the input data, it should default to False
124+
data_without_deactivation = {"x": 1.0, "y": 2.0, "z": 3.0}
125+
result = schema.load(data_without_deactivation)
126+
assert result["deactivation"] is False
127+
128+
# Test 3: When deactivation is explicitly set to True, it should remain True
129+
data_with_true = {"x": 1.0, "y": 2.0, "z": 3.0, "deactivation": True}
130+
result = schema.load(data_with_true)
131+
assert result["deactivation"] is True
132+
133+
# Test 4: When deactivation is explicitly set to False, it should remain False
134+
data_with_false = {"x": 1.0, "y": 2.0, "z": 3.0, "deactivation": False}
135+
result = schema.load(data_with_false)
136+
assert result["deactivation"] is False

0 commit comments

Comments
 (0)