mongoengine/tests
Nigel McNie 4c9e90732e Apply defaults to fields with None value at 'set' time.
If a field has a default, and you explicitly set it to None, the
behaviour before this patch was very confusing:

    class Person(Document):
        created = DateTimeField(default=datetime.datetime.utcnow)

    >>> p = Person(created=None)
    >>> p.created
    datetime.datetime(2013, 5, 30, 0, 18, 20, 242628)
    >>> p.created
    datetime.datetime(2013, 5, 30, 0, 18, 20, 995248)
    >>> p.created
    datetime.datetime(2013, 5, 30, 0, 18, 21, 370578)

It would be stored as None, and then at 'get' time, the default would be
applied. As you can see, if the default is a generator, this leads to some
crazy behaviour.

There's an argument that if I asked it to be set to None, why not respect that?
But I don't think that's how the rest of mongoengine seems to work (for
example, setting a field to None seems to mean it doesn't even get set in mongo
- as opposed to being set but with a 'null' value). Besides, as the code shows
above, you'd expect p.created to return None. So clearly, mongoengine is
already expecting None to mean 'default' where a default is available.

This bug also interacts nastily with required=True - if you're forcibly setting
the field to None, then at validation time, the None will fail validation
despite a perfectly valid default being available.

With this patch, when the field is set, the default is immediately applied.
This means any generation happens once, the getter always returns the same
value, and 'required' validation always respects the default.

Note: this breakage seems to be new since mongoengine 0.8.
2013-05-30 16:37:40 +12:00
..
all_warnings Cascading saves now default to off (#291) 2013-04-25 10:24:33 +00:00
document update pickling test case to show the error 2013-05-20 17:40:56 -07:00
fields Apply defaults to fields with None value at 'set' time. 2013-05-30 16:37:40 +12:00
migration DecimalField now stores as float not string (#289) 2013-04-25 15:39:57 +00:00
queryset test reference to a custom pk doc 2013-05-13 21:42:20 -07:00
__init__.py UUIDField now stores as a binary by default (#292) 2013-04-25 13:43:56 +00:00
fixtures.py Updated pickling (#316) 2013-05-20 10:04:17 +00:00
test_connection.py Removed import with from future 2013-05-01 08:48:14 +00:00
test_context_managers.py Added no_sub_classes context manager and queryset helper (#312) 2013-05-10 15:05:16 +00:00
test_dereference.py Removed import with from future 2013-05-01 08:48:14 +00:00
test_django.py Fixing django tests for py 2.6 2013-05-21 09:42:22 +00:00
test_jinja.py Querysets now utilises a local cache 2013-05-10 13:57:32 +00:00
test_replicaset_connection.py Updated tests 2013-01-28 13:40:28 +00:00
test_signals.py ReferenceField now store ObjectId's by default rather than DBRef (#290) 2013-04-24 12:14:34 +00:00