Skip to content

Empty model instances shouldn't evaluate to False #23

@andialbrecht

Description

@andialbrecht

The behavior of empty model instances is unexpected IMO. When you create a new model instance without any properties set, it evaluates to False in boolean expression. For example the following code snippet raises an assertion error either if some_id is None or some_id = 'DOES_NOT_EXIST':

if some_id is None:
obj = MyModel() # create a new instance
else:
obj = MyModel.collection.find_one({'_id': ObjectId(some_id)}) # retrieve from datastore
assert obj

I would have expected that only the second path raises an assertion error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions