mirror of
https://github.com/makeplane/plane.git
synced 2025-12-16 11:57:56 +01:00
[WEB-5285] feat: enhance ChangeTrackerMixin to capture changed fields on save (#8270)
- Added an override for the save method in ChangeTrackerMixin to store changed fields before resetting tracking. - Implemented a new method, _reset_tracked_fields, to ensure subsequent saves detect changes relative to the last saved state. - Updated IssueComment to utilize _changes_on_save for determining changed fields, improving accuracy in tracking modifications.
This commit is contained in:
committed by
GitHub
parent
079a624006
commit
8bb7ebb725
@@ -188,3 +188,30 @@ class ChangeTrackerMixin:
|
||||
all non-deferred fields).
|
||||
"""
|
||||
return self._original_values
|
||||
|
||||
def save(self, *args: Any, **kwargs: Any) -> None:
|
||||
"""
|
||||
Override save to automatically capture changed fields and reset tracking.
|
||||
|
||||
Before saving, the current changed_fields are captured and stored in
|
||||
_changes_on_save. After saving, the tracked fields are reset so
|
||||
that subsequent saves correctly detect changes relative to the last
|
||||
saved state, not the original load-time state.
|
||||
|
||||
Models that need to access the changed fields after save (e.g., for
|
||||
syncing related models) can use self._changes_on_save.
|
||||
"""
|
||||
self._changes_on_save = self.changed_fields
|
||||
super().save(*args, **kwargs)
|
||||
self._reset_tracked_fields()
|
||||
|
||||
def _reset_tracked_fields(self) -> None:
|
||||
"""
|
||||
Reset the tracked field values to the current state.
|
||||
|
||||
This is called automatically after save() to ensure that subsequent
|
||||
saves correctly detect changes relative to the last saved state,
|
||||
rather than the original load-time state.
|
||||
"""
|
||||
self._original_values = {}
|
||||
self._track_fields()
|
||||
|
||||
@@ -513,10 +513,12 @@ class IssueComment(ChangeTrackerMixin, ProjectBaseModel):
|
||||
"comment_json": "description_json",
|
||||
}
|
||||
|
||||
# Use _changes_on_save which is captured by ChangeTrackerMixin.save()
|
||||
# before the tracked fields are reset
|
||||
changed_fields = {
|
||||
desc_field: getattr(self, comment_field)
|
||||
for comment_field, desc_field in field_mapping.items()
|
||||
if self.has_changed(comment_field)
|
||||
if comment_field in self._changes_on_save
|
||||
}
|
||||
|
||||
# Update description only if comment fields changed
|
||||
|
||||
Reference in New Issue
Block a user