Fixes bug using positional operator to update embedded documents.
append_field wasn't getting reset to True in the loop, so fields wouldn't get appended to clean_fields after str was encountered [#354]
This commit is contained in:
		
				
					committed by
					
						 Ross Lawley
						Ross Lawley
					
				
			
			
				
	
			
			
			
						parent
						
							5aeee9deb2
						
					
				
				
					commit
					34646a414c
				
			
							
								
								
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
									
									
									
									
								
							| @@ -73,4 +73,5 @@ that much better: | |||||||
|  * Julien Rebetez |  * Julien Rebetez | ||||||
|  * Marc Tamlyn |  * Marc Tamlyn | ||||||
|  * Karim Allah |  * Karim Allah | ||||||
|  |  * Adam Parrish | ||||||
|  |  | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ Changelog | |||||||
| Changes in dev | Changes in dev | ||||||
| ============== | ============== | ||||||
|  |  | ||||||
|  | - Fixed positional operator when replacing embedded documents | ||||||
| - Added Non-Django Style choices back (you can have either) | - Added Non-Django Style choices back (you can have either) | ||||||
| - Fixed __repr__ of a sliced queryset | - Fixed __repr__ of a sliced queryset | ||||||
| - Added recursive validation error of documents / complex fields | - Added recursive validation error of documents / complex fields | ||||||
|   | |||||||
| @@ -1276,8 +1276,8 @@ class QuerySet(object): | |||||||
|                 parts = [] |                 parts = [] | ||||||
|  |  | ||||||
|                 cleaned_fields = [] |                 cleaned_fields = [] | ||||||
|                 append_field = True |  | ||||||
|                 for field in fields: |                 for field in fields: | ||||||
|  |                     append_field = True | ||||||
|                     if isinstance(field, str): |                     if isinstance(field, str): | ||||||
|                         # Convert the S operator to $ |                         # Convert the S operator to $ | ||||||
|                         if field == 'S': |                         if field == 'S': | ||||||
|   | |||||||
| @@ -378,6 +378,34 @@ class QuerySetTest(unittest.TestCase): | |||||||
|         self.assertRaises(OperationError, update_nested) |         self.assertRaises(OperationError, update_nested) | ||||||
|         Simple.drop_collection() |         Simple.drop_collection() | ||||||
|  |  | ||||||
|  |     def test_update_using_positional_operator_embedded_document(self): | ||||||
|  |         """Ensure that the embedded documents can be updated using the positional | ||||||
|  |         operator.""" | ||||||
|  |  | ||||||
|  |         class Vote(EmbeddedDocument): | ||||||
|  |             score = IntField() | ||||||
|  |  | ||||||
|  |         class Comment(EmbeddedDocument): | ||||||
|  |             by = StringField() | ||||||
|  |             votes = EmbeddedDocumentField(Vote) | ||||||
|  |  | ||||||
|  |         class BlogPost(Document): | ||||||
|  |             title = StringField() | ||||||
|  |             comments = ListField(EmbeddedDocumentField(Comment)) | ||||||
|  |  | ||||||
|  |         BlogPost.drop_collection() | ||||||
|  |  | ||||||
|  |         c1 = Comment(by="joe", votes=Vote(score=3)) | ||||||
|  |         c2 = Comment(by="jane", votes=Vote(score=7)) | ||||||
|  |  | ||||||
|  |         BlogPost(title="ABC", comments=[c1, c2]).save() | ||||||
|  |  | ||||||
|  |         BlogPost.objects(comments__by="joe").update(set__comments__S__votes=Vote(score=4)) | ||||||
|  |  | ||||||
|  |         post = BlogPost.objects.first() | ||||||
|  |         self.assertEquals(post.comments[0].by, 'joe') | ||||||
|  |         self.assertEquals(post.comments[0].votes.score, 4) | ||||||
|  |  | ||||||
|     def test_mapfield_update(self): |     def test_mapfield_update(self): | ||||||
|         """Ensure that the MapField can be updated.""" |         """Ensure that the MapField can be updated.""" | ||||||
|         class Member(EmbeddedDocument): |         class Member(EmbeddedDocument): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user