Skip to content

Commit bad7a3d

Browse files
authored
[FIX] remove info fields (#685)
* remove has_coordinates and has_images from info * remove studyset * always join the user table * fix broken test
1 parent 7f2ed5c commit bad7a3d

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

store/neurostore/resources/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ def __init__(self):
433433
def view_search(self, q, args):
434434
return q
435435

436-
def join_tables(self, q):
436+
def join_tables(self, q, args):
437437
if self._model is User:
438438
return q
439439
return q.options(joinedload("user"))
@@ -504,8 +504,7 @@ def search(self):
504504
q = q.order_by(getattr(attr, desc)())
505505

506506
# join the relevant tables for output
507-
if not args.get("flat"):
508-
q = self.join_tables(q)
507+
q = self.join_tables(q, args)
509508

510509
pagination_query = q.paginate(
511510
page=args["page"],

store/neurostore/resources/data.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,11 @@ def view_search(self, q, args):
262262

263263
return q
264264

265-
def join_tables(self, q):
265+
def join_tables(self, q, args):
266266
"join relevant tables to speed up query"
267-
q = q.options(joinedload("versions"))
268-
return super().join_tables(q)
267+
if not args.get("flat"):
268+
q = q.options(joinedload("versions"))
269+
return super().join_tables(q, args)
269270

270271
def post(self):
271272
from .base import clear_cache
@@ -402,11 +403,12 @@ def view_search(self, q, args):
402403
)
403404
return q
404405

405-
def join_tables(self, q):
406+
def join_tables(self, q, args):
406407
"join relevant tables to speed up query"
407-
q = q.options(joinedload("base_study"))
408-
q = q.options(joinedload("analyses"))
409-
return super().join_tables(q)
408+
if not args.get("flat"):
409+
q = q.options(joinedload("base_study"))
410+
q = q.options(joinedload("analyses"))
411+
return super().join_tables(q, args)
410412

411413
def serialize_records(self, records, args, exclude=tuple()):
412414
if args.get("studyset_owner"):

store/neurostore/schemas/data.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class BaseDataSchema(BaseSchema):
167167
attribute="user_id", dump_only=True, metadata={"info_field": True}
168168
)
169169
username = fields.String(
170-
attribute="user.name", dump_only=True, metadata={"info_field": True}
170+
attribute="user.name", dump_only=True, metadata={"info_field": True}, default=None,
171171
)
172172

173173

@@ -337,15 +337,15 @@ class StudySchema(BaseDataSchema):
337337
"id",
338338
many=True,
339339
dump_only=True,
340-
metadata={"id_field": True, "info_field": True},
340+
metadata={"id_field": True},
341341
)
342342
base_study = fields.Pluck(
343343
"BaseStudySchema",
344344
"id",
345345
dump_only=True,
346346
)
347-
has_coordinates = fields.Bool(dump_only=True, metadata={"info_field": True})
348-
has_images = fields.Bool(dump_only=True, metadata={"info_field": True})
347+
has_coordinates = fields.Bool(dump_only=True)
348+
has_images = fields.Bool(dump_only=True)
349349
source_updated_at = fields.DateTime(dump_only=True, allow_none=True)
350350

351351
class Meta:

store/neurostore/tests/api/test_base_studies.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Test Base Study Endpoint"""
22
from neurostore.models import BaseStudy, Analysis
3+
from neurostore.schemas import StudySchema
34

45

56
def test_post_list_of_studies(auth_client, ingest_neuroquery):
@@ -56,10 +57,18 @@ def test_info_base_study(auth_client, ingest_neurosynth, session):
5657

5758
assert single_info_resp.status_code == 200
5859
assert single_reg_resp.status_code == 200
59-
info_fields = ["has_coordinates", "has_images", "studysets"]
60-
for field in info_fields:
61-
assert field in single_info_resp.json()["versions"][0]
62-
assert "id" in single_info_resp.json()["versions"][0]
60+
61+
info_fields = [
62+
f
63+
for f, v in StudySchema._declared_fields.items()
64+
if v.metadata.get("info_field")
65+
]
66+
67+
study = single_info_resp.json()["versions"][0]
68+
69+
for f in info_fields:
70+
assert f in study
71+
6372
assert isinstance(single_reg_resp.json()["versions"][0], str)
6473

6574

0 commit comments

Comments
 (0)