Skip to content

Commit

Permalink
fix: ContentMetadata.bulk_update() changes the modified value
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Jul 24, 2024
1 parent 0c83224 commit 8598067
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions enterprise_catalog/apps/catalog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,26 @@ def get_xapi_activity_id(self, content_resource, content_key):
return xapi_activity_id


class ContentMetadataManager(models.Manager):
"""
Customer manager for ContentMetadata that forces the `modified` field
to be updated during `bulk_update()`.
"""

def bulk_update(self, objs, fields, batch_size=None):
"""
Updates the `modified` time of each object, and then
does the usual bulk update, with `modified` as also
a field to save.
"""
last_modified = localized_utcnow()
for obj in objs:
obj.modified = last_modified
fields += ['modified']

super().bulk_update(objs, fields, batch_size=batch_size)


class ContentMetadata(TimeStampedModel):
"""
Stores the JSON metadata for a piece of content, such as a course, course run, or program.
Expand Down Expand Up @@ -556,6 +576,8 @@ class ContentMetadata(TimeStampedModel):

history = HistoricalRecords()

objects = ContentMetadataManager()

class Meta:
verbose_name = _("Content Metadata")
verbose_name_plural = _("Content Metadata")
Expand Down

0 comments on commit 8598067

Please sign in to comment.