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

getattr after setattr of None does not return None #505

Closed
mitar opened this issue May 18, 2012 · 1 comment
Closed

getattr after setattr of None does not return None #505

mitar opened this issue May 18, 2012 · 1 comment

Comments

@mitar
Copy link

mitar commented May 18, 2012

Calling setattr with None value does internally store that None in self._data, but later calls of getattr does not return None, but previous version of the field. This is quite unexpected as you would assume that getattr after successful setattr will return the same value.

In code, see implementation of __setattr__ in BaseDocument:

        # Handle None values for required fields
        if value is None and name in getattr(self, '_fields', {}):
            self._data[name] = value
            if hasattr(self, '_changed_fields'):
                self._mark_as_changed(name)
            return

So if value is None, then self._data is set, but after that return is invoked. So program flow does not get to:

super(BaseDocument, self).__setattr__(name, value)

So calling later on getattr for the same field returns old value.

rozza added a commit to MongoEngine/mongoengine that referenced this issue Jun 19, 2012
@rozza
Copy link

rozza commented Jun 19, 2012

Thanks @mitar for the ticket - will be in 0.6.11 out today

@rozza rozza closed this as completed Jun 19, 2012
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