You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe not an issue and I'm just missing something. I'll try to explain me with some code
I have a situation like this:
classUserStatusResource(ModelResource):
classMeta:
model=UserStatusclassUserResource(ModelResource):
classMeta:
model=UserclassSchema:
# id_user_status is an Integer ForeignKey referencing a single UserStatus row# user_status is a sqlalchemy.orm.relationship()# Here I want the UserStatus object embedded in the User repr, and not just a $refuser_status=fields.Inline('user_status')
Now, I'm expecting that when I fetch a user instance (GET /user/), if the instance has the id_user_status set to None (and consequently user_status relationship also returns None), the value of the key user_status to be None.
Instead I get an object with every field of the user-status resource set to None (exception made for the $uri that is set to /user-status/None)
I tried passing nullable=True and default=None to Inline(), but nothing changes.
Is this the correct behaviour? Is there a way in which I can change this behaviour and simply get a null value as a representation for None?
Thanks
The text was updated successfully, but these errors were encountered:
It seems to me that it's not correct behavior, cause resource bound to invalid uri. You can get a null value with that patch:
--- schema.py.old 2019-08-19 15:12:04.712622200 +0400
+++ schema.py 2019-08-19 15:07:01.547122200 +0400
@@ -213,6 +213,8 @@
return all(((i.default is not None) or i.nullable for i in (self.fields or {}).values()))
def format(self, item):
+ if item is None:
+ return None
return OrderedDict((key, field.output(key, item)) for key, field in self.fields.items() if 'r' in field.io)
def convert(self, instance, update=False, pre_resolved_properties=None, patchable=False, strict=False):
Maybe not an issue and I'm just missing something. I'll try to explain me with some code
I have a situation like this:
Now, I'm expecting that when I fetch a user instance (GET /user/), if the instance has the id_user_status set to None (and consequently user_status relationship also returns None), the value of the key
user_status
to be None.Instead I get an object with every field of the user-status resource set to None (exception made for the $uri that is set to
/user-status/None
)I tried passing
nullable=True
anddefault=None
toInline()
, but nothing changes.Is this the correct behaviour? Is there a way in which I can change this behaviour and simply get a null value as a representation for None?
Thanks
The text was updated successfully, but these errors were encountered: