def schema_from_umongo_get_attribute(self, attr, obj, default):
"""
Overwrite default `Schema.get_attribute` method by this one to access
umongo missing fields instead of returning `None`.
example::
class MySchema(marshsmallow.Schema):
get_attribute = schema_from_umongo_get_attribute
# Define the rest of your schema
...
"""
ret = MaSchema.get_attribute(self, attr, obj, default)
if ret is None and ret is not default and attr in obj.schema.fields:
raw_ret = obj._data.get(attr)
return default if raw_ret is missing else raw_ret
else:
return ret
评论列表
文章目录