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

to_primitive should always return None when value is None #447

Conversation

alexhayes
Copy link

If using a DecimalType and you supply a None value, when calling to_primitive it returns 'None' (string).

This PR ensures that None is returned for all fields if the value of the field is None.

…_primitive returning str 'None' for DecimalType et al.
@rmb938 rmb938 mentioned this pull request Dec 8, 2016
@lkraider
Copy link
Contributor

lkraider commented Mar 16, 2017

Not sure about the use case here, when you serialize a Model the fields that have None will be in the output (unless serialize_when_none is False). This works today:

def test_none_to_primitive():
    class Foo(Model):
        i = IntType()
        s = StringType()
        d = DecimalType()
        u = UUIDType()

    class Bar(Foo):
        class Options:
            serialize_when_none = False

    f = Foo()
    assert f.serialize() == {'i': None, 's': None, 'd': None, 'u': None}
    b = Bar()
    assert b.serialize() == {}

Copy link
Contributor

@lkraider lkraider left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the use case here. Please provide some tests that identify the usefulness of this code. Please see my previous comment on the PR for a counter example why I think this isn't needed.

@lkraider lkraider closed this May 23, 2017
@lkraider lkraider reopened this May 23, 2017
@lkraider
Copy link
Contributor

Closing, but please open a new Issue or PR in case you think this is still needed.

@lkraider lkraider closed this May 31, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants