Fixed EmbeddedDocument with ReferenceField equality issue (#502)

This commit is contained in:
Ross Lawley 2013-11-29 12:46:18 +00:00
parent bb56f92213
commit a2a698ab0e
4 changed files with 21 additions and 1 deletions

View File

@ -186,3 +186,4 @@ that much better:
* rfkrocktk (https://github.com/rfkrocktk) * rfkrocktk (https://github.com/rfkrocktk)
* Gustavo Andrés Angulo (https://github.com/woakas) * Gustavo Andrés Angulo (https://github.com/woakas)
* Dmytro Popovych (https://github.com/drudim) * Dmytro Popovych (https://github.com/drudim)
* Tom (https://github.com/tomprimozic)

View File

@ -4,6 +4,7 @@ Changelog
Changes in 0.8.5 Changes in 0.8.5
================ ================
- Fixed EmbeddedDocument with ReferenceField equality issue (#502)
- Fixed GenericReferenceField serialization order (#499) - Fixed GenericReferenceField serialization order (#499)
- Fixed count and none bug (#498) - Fixed count and none bug (#498)
- Fixed bug with .only() and DictField with digit keys (#496) - Fixed bug with .only() and DictField with digit keys (#496)

View File

@ -66,7 +66,7 @@ class EmbeddedDocument(BaseDocument):
def __eq__(self, other): def __eq__(self, other):
if isinstance(other, self.__class__): if isinstance(other, self.__class__):
return self._data == other._data return self.to_mongo() == other.to_mongo()
return False return False
def __ne__(self, other): def __ne__(self, other):

View File

@ -2392,6 +2392,24 @@ class InstanceTest(unittest.TestCase):
system = System.objects.first() system = System.objects.first()
self.assertEqual("UNDEFINED", system.nodes["node"].parameters["param"].macros["test"].value) self.assertEqual("UNDEFINED", system.nodes["node"].parameters["param"].macros["test"].value)
def test_embedded_document_equality(self):
class Test(Document):
field = StringField(required=True)
class Embedded(EmbeddedDocument):
ref = ReferenceField(Test)
Test.drop_collection()
test = Test(field='123').save() # has id
e = Embedded(ref=test)
f1 = Embedded._from_son(e.to_mongo())
f2 = Embedded._from_son(e.to_mongo())
self.assertEqual(f1, f2)
f1.ref # Dereferences lazily
self.assertEqual(f1, f2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()