marshmallow_bonus.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:umongo 作者: Scille 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号