Error in GenericReferenceField serialization was fixed
This commit is contained in:
parent
1145c72b01
commit
f2c25b4744
@ -1022,7 +1022,10 @@ class GenericReferenceField(BaseField):
|
|||||||
id_ = id_field.to_mongo(id_)
|
id_ = id_field.to_mongo(id_)
|
||||||
collection = document._get_collection_name()
|
collection = document._get_collection_name()
|
||||||
ref = DBRef(collection, id_)
|
ref = DBRef(collection, id_)
|
||||||
return {'_cls': document._class_name, '_ref': ref}
|
return SON((
|
||||||
|
('_cls', document._class_name),
|
||||||
|
('_ref', ref)
|
||||||
|
))
|
||||||
|
|
||||||
def prepare_query_value(self, op, value):
|
def prepare_query_value(self, op, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
|
@ -1904,6 +1904,37 @@ class FieldTest(unittest.TestCase):
|
|||||||
Post.drop_collection()
|
Post.drop_collection()
|
||||||
User.drop_collection()
|
User.drop_collection()
|
||||||
|
|
||||||
|
def test_generic_reference_list_item_modification(self):
|
||||||
|
"""Ensure that modifications of related documents (through generic reference) don't influence on querying
|
||||||
|
"""
|
||||||
|
class Post(Document):
|
||||||
|
title = StringField()
|
||||||
|
|
||||||
|
class User(Document):
|
||||||
|
username = StringField()
|
||||||
|
bookmarks = ListField(GenericReferenceField())
|
||||||
|
|
||||||
|
Post.drop_collection()
|
||||||
|
User.drop_collection()
|
||||||
|
|
||||||
|
post_1 = Post(title="Behind the Scenes of the Pavement Reunion")
|
||||||
|
post_1.save()
|
||||||
|
|
||||||
|
user = User(bookmarks=[post_1])
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
post_1.title = "Title was modified"
|
||||||
|
user.username = "New username"
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
user = User.objects(bookmarks__all=[post_1]).first()
|
||||||
|
|
||||||
|
self.assertIsNotNone(user)
|
||||||
|
self.assertEqual(user.bookmarks[0], post_1)
|
||||||
|
|
||||||
|
Post.drop_collection()
|
||||||
|
User.drop_collection()
|
||||||
|
|
||||||
def test_binary_fields(self):
|
def test_binary_fields(self):
|
||||||
"""Ensure that binary fields can be stored and retrieved.
|
"""Ensure that binary fields can be stored and retrieved.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user