119 Commits

Author SHA1 Message Date
Ross Lawley
5447c6e947 DateTimeField now auto converts valid datetime isostrings into dates (#343) 2013-06-04 09:08:13 +00:00
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
Paul Swartz
c0571beec8 fix change tracking for ComplexBaseFields 2013-05-28 17:19:46 -04:00
Paul Swartz
1302316eb0 add some tests 2013-05-28 16:08:33 -04:00
Wilson Júnior
bc92f78afb fixes for value_decorator 2013-05-16 13:12:49 -03:00
Wilson Júnior
f7e22d2b8b fixes for get_next_value 2013-05-16 13:05:07 -03:00
Wilson Júnior
10e0b1daec Merge branch 'master' of https://github.com/MongoEngine/mongoengine 2013-05-16 12:50:47 -03:00
Wilson Júnior
731d8fc6be added get_next_value to SequenceField 2013-05-16 12:50:34 -03:00
Ross Lawley
e58b3390aa Removed import with from future 2013-05-01 08:48:14 +00:00
Ross Lawley
9c1cd81adb Add support for new geojson fields, indexes and queries (#299) 2013-04-30 14:46:23 +00:00
Ross Lawley
85b81fb12a If values cant be compared mark as changed (#287) 2013-04-29 10:36:11 +00:00
Ross Lawley
5e94637adc DecimalField now stores as float not string (#289) 2013-04-25 15:39:57 +00:00
Ross Lawley
ac6e793bbe UUIDField now stores as a binary by default (#292) 2013-04-25 13:43:56 +00:00
Ross Lawley
94d1e566c0 Added SequenceField.set_next_value(value) helper (#159) 2013-04-23 14:44:17 +00:00
Ross Lawley
51e50bf0a9 Merge branch 'master' into 0.8M
Conflicts:
	AUTHORS
	docs/django.rst
	mongoengine/base.py
	mongoengine/queryset.py
	tests/fields/fields.py
	tests/queryset/queryset.py
	tests/test_dereference.py
	tests/test_document.py
2013-04-17 11:57:53 +00:00
Ross Lawley
39dac7d4db Fix file open rules 2013-01-28 16:26:01 +00:00
Ross Lawley
3208a7f15d Merge fix tests 2013-01-28 14:28:40 +00:00
Ross Lawley
8eda52e8e0 Merge branch 'master' of https://github.com/malderete/mongoengine into 214
Conflicts:
	AUTHORS
	mongoengine/base.py
	tests/fields/fields.py
2013-01-28 14:27:17 +00:00
Ross Lawley
c5b047d0cd Fixed GridFSProxy __getattr__ behaviour (#196) 2012-12-21 11:55:05 +00:00