@@ -67,8 +67,21 @@ def _serialize(self, value, attr, obj, **kwargs):
6767 if self .metadata .get ("nested" , None ) is False
6868 else self .context .get ("nested" )
6969 )
70+ info = self .context .get ("info" )
71+ if info :
72+ schema = self .schema
73+ info_fields = [
74+ field
75+ for field , f_obj in schema ._declared_fields .items ()
76+ if f_obj .metadata .get ("info_field" )
77+ ]
78+ schema .only = schema .set_class (info_fields )
79+ # set exclude to an empty set
80+ schema .exclude = schema .set_class ()
81+ schema ._init_fields ()
82+
7083 nested_attr = self .metadata .get ("pluck" )
71- if nested :
84+ if nested or info :
7285 many = self .schema .many or self .many
7386 nested_obj = getattr (obj , self .data_key or self .name )
7487 return self .schema .dump (nested_obj , many = many )
@@ -115,11 +128,13 @@ def _deserialize(self, value, attr, data, **kwargs):
115128
116129
117130class BaseSchema (Schema ):
118- id = PGSQLString ()
131+ id = PGSQLString (metadata = { "info_field" : True } )
119132 created_at = fields .DateTime ()
120133 updated_at = fields .DateTime (allow_none = True )
121134 user_id = fields .String (data_key = "user" )
122- username = fields .String (attribute = "user.name" , dump_only = True )
135+ username = fields .String (
136+ attribute = "user.name" , dump_only = True , metadata = {"info_field" : True }
137+ )
123138
124139
125140class ConditionSchema (Schema ):
@@ -284,8 +299,8 @@ def process_data(self, data, **kwargs):
284299
285300
286301class MetaAnalysisSchema (BaseSchema ):
287- name = fields .String (allow_none = True )
288- description = fields .String (allow_none = True )
302+ name = fields .String (allow_none = True , metadata = { "info_field" : True } )
303+ description = fields .String (allow_none = True , metadata = { "info_field" : True } )
289304 provenance = fields .Dict (allow_none = True )
290305 specification_id = StringOrNested (SpecificationSchema , data_key = "specification" )
291306 neurostore_analysis = fields .Nested ("NeurostoreAnalysisSchema" , dump_only = True )
@@ -324,6 +339,8 @@ class MetaAnalysisSchema(BaseSchema):
324339
325340 @post_dump
326341 def create_neurostore_url (self , data , ** kwargs ):
342+ if self .context .get ("info" ):
343+ return data
327344 if data .get ("neurostore_analysis" , None ) and data ["neurostore_analysis" ].get (
328345 "neurostore_id" , None
329346 ):
0 commit comments