@@ -183,7 +183,7 @@ def bulk_invalidate_get_cached_checksum(cls, query_params):
183183 for instance in cls .objects .only ("id" ).filter (** query_params ).iterator ():
184184 has_changed = instance .update_status_if_checksum_changed ()
185185 if has_changed :
186- instance .get_cached_checksum . invalidate ( instance )
186+ instance .invalidate_checksum_cache ( )
187187
188188 @classmethod
189189 def get_template_model (cls ):
@@ -573,10 +573,10 @@ def clean(self):
573573 def save (self , * args , ** kwargs ):
574574 created = self ._state .adding
575575 # check if config has been modified (so we can emit signals)
576- if not created :
576+ if created :
577+ self .checksum_db = self .checksum
578+ else :
577579 self ._check_changes ()
578- self ._invalidate_backend_instance_cache ()
579- self .checksum_db = self .checksum
580580 self ._just_created = created
581581 result = super ().save (* args , ** kwargs )
582582 # add default templates if config has just been created
@@ -620,17 +620,12 @@ def _check_changes(self):
620620 if self .backend != current .backend :
621621 # storing old backend to send backend change signal after save
622622 self ._old_backend = current .backend
623- self ._invalidate_backend_instance_cache ()
624- if self .checksum != current .checksum :
625- if self .status != "modified" :
626- self .set_status_modified (save = False )
627- else :
628- # config modified signal is always sent
629- # regardless of the current status
630- self ._send_config_modified_after_save = True
623+ self .update_status_if_checksum_changed (
624+ save = False ,
625+ )
631626
632627 def update_status_if_checksum_changed (
633- self , save = True , send_config_modified_signal = True
628+ self , save = True , update_checksum_db = True , send_config_modified_signal = True
634629 ):
635630 """
636631 Updates the instance status if its checksum has changed.
@@ -649,7 +644,11 @@ def update_status_if_checksum_changed(
649644 extra_update_fields = ["checksum_db" ],
650645 )
651646 else :
652- self ._update_checksum_db (new_checksum = self .checksum_db )
647+ if update_checksum_db :
648+ self ._update_checksum_db (new_checksum = self .checksum_db )
649+ if send_config_modified_signal :
650+ self ._send_config_modified_after_save = True
651+ self .invalidate_checksum_cache ()
653652 return checksum_changed
654653
655654 def _has_configuration_checksum_changed (self ):
@@ -758,7 +757,7 @@ def set_status_modified(
758757 ):
759758 if send_config_modified_signal :
760759 self ._send_config_modified_after_save = True
761- self ._set_status ("modified" , save , extra_update_fields )
760+ self ._set_status ("modified" , save , extra_update_fields = extra_update_fields )
762761
763762 def set_status_applied (self , save = True ):
764763 self ._set_status ("applied" , save )
@@ -790,12 +789,14 @@ def deactivate(self):
790789 # otherwise, the "enforce_required_templates" and "add_default_templates"
791790 # methods would re-add required/default templates.
792791 # The "templates_changed" receiver skips post_clear action. Thus,
793- # we need to update the checksum_db field manually.
792+ # we need to update the checksum_db field manually and invalidate
793+ # the cache.
794794 self .config = {}
795795 self .set_status_deactivating (save = False )
796796 self .templates .clear ()
797797 self ._invalidate_backend_instance_cache ()
798798 self .checksum_db = self .checksum
799+ self .invalidate_checksum_cache ()
799800 self .save ()
800801 if old_checksum == self .checksum_db :
801802 # Accelerate deactivation if the configuration remains
0 commit comments