Test case and proposed solution for #2484
This commit is contained in:
		
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -259,3 +259,4 @@ that much better: | |||||||
|  * Agustin Barto (https://github.com/abarto) |  * Agustin Barto (https://github.com/abarto) | ||||||
|  * Stankiewicz Mateusz (https://github.com/mas15) |  * Stankiewicz Mateusz (https://github.com/mas15) | ||||||
|  * Felix Schultheiß (https://github.com/felix-smashdocs) |  * Felix Schultheiß (https://github.com/felix-smashdocs) | ||||||
|  |  * Jan Stein (https://github.com/janste63) | ||||||
|   | |||||||
| @@ -7,6 +7,7 @@ Development | |||||||
| =========== | =========== | ||||||
| - (Fill this out as you fix issues and develop your features). | - (Fill this out as you fix issues and develop your features). | ||||||
| - Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471 | - Bugfix: manually setting SequenceField in DynamicDocument doesn't increment the counter #2471 | ||||||
|  | - Bug fix: ignore LazyReferenceFields when clearing _changed_fields #2484 | ||||||
|  |  | ||||||
| Changes in 0.22.1 | Changes in 0.22.1 | ||||||
| ================= | ================= | ||||||
|   | |||||||
| @@ -615,7 +615,9 @@ class BaseDocument: | |||||||
|     def _get_changed_fields(self): |     def _get_changed_fields(self): | ||||||
|         """Return a list of all fields that have explicitly been changed.""" |         """Return a list of all fields that have explicitly been changed.""" | ||||||
|         EmbeddedDocument = _import_class("EmbeddedDocument") |         EmbeddedDocument = _import_class("EmbeddedDocument") | ||||||
|  |         LazyReferenceField = _import_class("LazyReferenceField") | ||||||
|         ReferenceField = _import_class("ReferenceField") |         ReferenceField = _import_class("ReferenceField") | ||||||
|  |         GenericLazyReferenceField = _import_class("GenericLazyReferenceField") | ||||||
|         GenericReferenceField = _import_class("GenericReferenceField") |         GenericReferenceField = _import_class("GenericReferenceField") | ||||||
|         SortedListField = _import_class("SortedListField") |         SortedListField = _import_class("SortedListField") | ||||||
|  |  | ||||||
| @@ -641,7 +643,13 @@ class BaseDocument: | |||||||
|                 changed_fields += [f"{key}{k}" for k in changed if k] |                 changed_fields += [f"{key}{k}" for k in changed if k] | ||||||
|             elif isinstance(data, (list, tuple, dict)): |             elif isinstance(data, (list, tuple, dict)): | ||||||
|                 if hasattr(field, "field") and isinstance( |                 if hasattr(field, "field") and isinstance( | ||||||
|                     field.field, (ReferenceField, GenericReferenceField) |                     field.field, | ||||||
|  |                     ( | ||||||
|  |                         LazyReferenceField, | ||||||
|  |                         ReferenceField, | ||||||
|  |                         GenericLazyReferenceField, | ||||||
|  |                         GenericReferenceField, | ||||||
|  |                     ), | ||||||
|                 ): |                 ): | ||||||
|                     continue |                     continue | ||||||
|                 elif isinstance(field, SortedListField) and field._ordering: |                 elif isinstance(field, SortedListField) and field._ordering: | ||||||
|   | |||||||
| @@ -375,6 +375,26 @@ class TestLazyReferenceField(MongoDBTestCase): | |||||||
|             assert isinstance(ref.author, LazyReference) |             assert isinstance(ref.author, LazyReference) | ||||||
|             assert isinstance(ref.author.id, ObjectId) |             assert isinstance(ref.author.id, ObjectId) | ||||||
|  |  | ||||||
|  |     def test_lazy_reference_in_list_with_changed_element(self): | ||||||
|  |         class Animal(Document): | ||||||
|  |             name = StringField() | ||||||
|  |             tag = StringField() | ||||||
|  |  | ||||||
|  |         class Ocurrence(Document): | ||||||
|  |             in_list = ListField(LazyReferenceField(Animal)) | ||||||
|  |  | ||||||
|  |         Animal.drop_collection() | ||||||
|  |         Ocurrence.drop_collection() | ||||||
|  |  | ||||||
|  |         animal1 = Animal(name="doggo").save() | ||||||
|  |  | ||||||
|  |         animal1.tag = "blue" | ||||||
|  |  | ||||||
|  |         occ = Ocurrence(in_list=[animal1]).save() | ||||||
|  |         animal1.save() | ||||||
|  |         assert isinstance(occ.in_list[0], LazyReference) | ||||||
|  |         assert occ.in_list[0].pk == animal1.pk | ||||||
|  |  | ||||||
|  |  | ||||||
| class TestGenericLazyReferenceField(MongoDBTestCase): | class TestGenericLazyReferenceField(MongoDBTestCase): | ||||||
|     def test_generic_lazy_reference_simple(self): |     def test_generic_lazy_reference_simple(self): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user