mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #28838 -- Fixed Model.save() crash if the base manager annotates with a related field.
This commit is contained in:
parent
cbac11f962
commit
8dc675d90f
3 changed files with 31 additions and 1 deletions
|
@ -617,6 +617,22 @@ class CustomManagersRegressTestCase(TestCase):
|
|||
book.refresh_from_db()
|
||||
self.assertEqual(book.title, 'Hi')
|
||||
|
||||
def test_save_clears_annotations_from_base_manager(self):
|
||||
"""Model.save() clears annotations from the base manager."""
|
||||
self.assertEqual(Book._meta.base_manager.name, 'annotated_objects')
|
||||
book = Book.annotated_objects.create(title='Hunting')
|
||||
Person.objects.create(
|
||||
first_name='Bugs', last_name='Bunny', fun=True,
|
||||
favorite_book=book, favorite_thing_id=1,
|
||||
)
|
||||
book = Book.annotated_objects.first()
|
||||
self.assertEqual(book.favorite_avg, 1) # Annotation from the manager.
|
||||
book.title = 'New Hunting'
|
||||
# save() fails if annotations that involve related fields aren't
|
||||
# cleared before the update query.
|
||||
book.save()
|
||||
self.assertEqual(Book.annotated_objects.first().title, 'New Hunting')
|
||||
|
||||
def test_delete_related_on_filtered_manager(self):
|
||||
"""Deleting related objects should also not be distracted by a
|
||||
restricted manager on the related object. This is a regression
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue