Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable is not working in to_struct() #140

Open
buriedguns opened this issue Dec 22, 2020 · 1 comment
Open

Nullable is not working in to_struct() #140

buriedguns opened this issue Dec 22, 2020 · 1 comment

Comments

@buriedguns
Copy link

buriedguns commented Dec 22, 2020

class Person(models.Base):
    nickname = fields.StringField(nullable=True)
person = Person()
>>> person.to_struct()
{
    'nickname': None,
}

If you try to reproduce the example above from your documentation (Person with nullable Nickname to_struct()) it will return nothing, and not a 'nickname': None.

That's because there's no nullable verification in parser.py to_struct() function. Could you add it please, like in the example below?

def to_struct(model):
    """Cast instance of model to python structure.

    :param model: Model to be casted.
    :rtype: ``dict``

    """
    model.validate()

    resp = {}
    for _, name, field in model.iterate_with_name():
        value = field.__get__(model)
        if value is None and not field.nullable:
            continue

        value = field.to_struct(value)
        resp[name] = value
    return resp
@beregond
Copy link
Collaborator

Hey, thanks @buriedguns - I understand the problem, will look into it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants