Fixed EmbeddedDocument with ReferenceField equality issue (#502)
This commit is contained in:
parent
bb56f92213
commit
a2a698ab0e
1
AUTHORS
1
AUTHORS
@ -186,3 +186,4 @@ that much better:
|
||||
* rfkrocktk (https://github.com/rfkrocktk)
|
||||
* Gustavo Andrés Angulo (https://github.com/woakas)
|
||||
* Dmytro Popovych (https://github.com/drudim)
|
||||
* Tom (https://github.com/tomprimozic)
|
@ -4,6 +4,7 @@ Changelog
|
||||
|
||||
Changes in 0.8.5
|
||||
================
|
||||
- Fixed EmbeddedDocument with ReferenceField equality issue (#502)
|
||||
- Fixed GenericReferenceField serialization order (#499)
|
||||
- Fixed count and none bug (#498)
|
||||
- Fixed bug with .only() and DictField with digit keys (#496)
|
||||
|
@ -66,7 +66,7 @@ class EmbeddedDocument(BaseDocument):
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, self.__class__):
|
||||
return self._data == other._data
|
||||
return self.to_mongo() == other.to_mongo()
|
||||
return False
|
||||
|
||||
def __ne__(self, other):
|
||||
|
@ -2392,6 +2392,24 @@ class InstanceTest(unittest.TestCase):
|
||||
system = System.objects.first()
|
||||
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__':
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user