hmarr / mongoengine

[Moved to mongoengine/mongoengine]
https://github.com/MongoEngine/mongoengine
MIT License
795 stars 20 forks source link

reload should return self and not obj #516

Open mitar opened 12 years ago

mitar commented 12 years ago

Document's reload should return self and not obj, as obj is just a temporary object and for chaining you expect that chained calls will be visible on the original object.

rozza commented 12 years ago

I was thinking that it shouldnt be harmful to return obj hence the original path, but I can see your point.

Have you got an example where it breaks things for you?

mitar commented 11 years ago

Here is an example where this is needed.

The main idea is, that if you add to object some custom attributes, which are not in the schema, you expect them to be there afterwards. But they are not. So something like this:

obj = Person.objects.all()[0]
obj._foo = 'bar'
val = obj.reload()
self.assertEqual(val._foo, 'bar')

In upper example, authentication caches which backend was used in user object, so this is lost on reload.