Add support for m2m changes in AbstractLogEntry.changes_str#798
Conversation
…ntry.changes_str property.
for more information, see https://pre-commit.ci
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #798 +/- ##
==========================================
+ Coverage 95.92% 96.33% +0.41%
==========================================
Files 35 35
Lines 1252 1256 +4
==========================================
+ Hits 1201 1210 +9
+ Misses 51 46 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks @marco-thirona for the PR. Could you please fix the failing test and add a change log entry? @2ykwang Could you please review the PR? |
|
Thanks for the PR! I'll review this over the weekend. @marco-thirona before that, could you please:
|
@2ykwang The test that was failing in the previous build is flaky, I'm afraid: I just added a changelog note, and now the builds are fine again. |
2ykwang
left a comment
There was a problem hiding this comment.
Thanks @marco-thirona
sorry for the late review. just a quick comment.
auditlog/models.py
Outdated
There was a problem hiding this comment.
@marco-thirona
small suggestion: Sequence includes str as well (though unlikely to cause issues in practice).
How about isinstance(value, (list, tuple)) to make the intent clearer?
also, adding a length check like len(value) == 2 might be nice.
There was a problem hiding this comment.
Great suggestions @2ykwang, I'll make these changes
2ykwang
left a comment
There was a problem hiding this comment.
Sorry for the late review! Left a small suggestion.
let me know what you think 😃
auditlog/models.py
Outdated
There was a problem hiding this comment.
for field, value in sorted(self.changes_dict.items()):
if isinstance(value, (list, tuple)) and len(value) == 2:
# handle regular field change
elif isinstance(value, dict) and value.get("type") == "m2m":
# handle m2m changeWhat do you think about restructuring it this way? Given the current design, mixed types won't occur,
but this would iterate only once and improve readability.
There was a problem hiding this comment.
True that log entries do not currently mix regular and m2m changes, though this approach looks cleaner indeed, so I'll restructure as you proposed. Thanks for the suggestion
|
and thank you for working on this! @marco-thirona |
|
@hramezani could you double-check this when you have a moment? |
|
Thanks both |
Fixes #585