diff --git a/course_discovery/apps/course_metadata/model_utils.py b/course_discovery/apps/course_metadata/model_utils.py index 82db02bae1..39ff215675 100644 --- a/course_discovery/apps/course_metadata/model_utils.py +++ b/course_discovery/apps/course_metadata/model_utils.py @@ -24,3 +24,19 @@ def has_model_changed(field_tracker, external_keys=None, excluded_fields=None): return len(changed) or any( item.has_changed for item in external_keys if hasattr(item, 'has_changed') ) + + +def should_history_be_skipped_on_save(obj, *args, **kwargs): + """ + Sets the parameter 'skip_history_on_save' if the object is not changed + Args: + obj: Any Model instance + parent_obj: parent object of the instance obj + """ + if not obj.has_changed: + setattr(obj, 'skip_history_when_saving', True) # pylint: disable=literal-used-as-attribute + + super(obj.__class__, obj).save(*args, **kwargs) + + if hasattr(obj, 'skip_history_when_saving'): + delattr(obj, 'skip_history_when_saving') # pylint: disable=literal-used-as-attribute diff --git a/course_discovery/apps/course_metadata/models.py b/course_discovery/apps/course_metadata/models.py index 7376da7c90..74e6b11628 100644 --- a/course_discovery/apps/course_metadata/models.py +++ b/course_discovery/apps/course_metadata/models.py @@ -48,7 +48,7 @@ from course_discovery.apps.course_metadata.constants import SUBDIRECTORY_SLUG_FORMAT_REGEX, PathwayType from course_discovery.apps.course_metadata.fields import AutoSlugWithSlashesField, HtmlField, NullHtmlField from course_discovery.apps.course_metadata.managers import DraftManager -from course_discovery.apps.course_metadata.model_utils import has_model_changed +from course_discovery.apps.course_metadata.model_utils import has_model_changed, should_history_be_skipped_on_save from course_discovery.apps.course_metadata.people import MarketingSitePeople from course_discovery.apps.course_metadata.publishers import ( CourseRunMarketingSitePublisher, ProgramMarketingSitePublisher @@ -1459,11 +1459,11 @@ def save(self, *args, **kwargs): and then need to update the boolean in the record based on conditional logic """ self.update_data_modified_timestamp() - super().save(*args, **kwargs) + should_history_be_skipped_on_save(self, *args, **kwargs) self.enterprise_subscription_inclusion = self._check_enterprise_subscription_inclusion() kwargs['force_insert'] = False kwargs['force_update'] = True - super().save(*args, **kwargs) + should_history_be_skipped_on_save(self, *args, **kwargs) # Course runs calculate enterprise subscription inclusion based off of their parent's status, so we need to # force a recalculation