Reorder operations in save() overrides
Accessing many-to-many relations before saving is no longer allowed. Reorder all operations consistently: 1. Validations 2. Modify own fields 3. Perform save by calling super().save() 4. Modify related objects and clear caches Especially clearing caches should be done after actually saving, otherwise the old data can be re-added immediately by another request before the new data is written.
This commit is contained in:
parent
47fdad9c87
commit
0d621b68e0
7 changed files with 32 additions and 20 deletions
|
@ -459,9 +459,10 @@ class Review(BookStatus):
|
|||
|
||||
def save(self, *args, **kwargs):
|
||||
"""clear rating caches"""
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
if self.book.parent_work:
|
||||
cache.delete(f"book-rating-{self.book.parent_work.id}")
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class ReviewRating(Review):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue