Skip to content

Ensure dirty-bit is updated when calling save on a syncable model with update_fields#326

Open
bjester wants to merge 3 commits intolearningequality:release-v0.8.xfrom
bjester:pls-save-fields
Open

Ensure dirty-bit is updated when calling save on a syncable model with update_fields#326
bjester wants to merge 3 commits intolearningequality:release-v0.8.xfrom
bjester:pls-save-fields

Conversation

@bjester
Copy link
Copy Markdown
Member

@bjester bjester commented May 1, 2026

Summary

  • Adds regression test that verified the issue scenario
  • Addresses the issue scenario by adding the dirty-bit field to update_fields when present
  • Bumps version and updates changelog

TODO

  • Have tests been written for the new code?
  • Has documentation been written/updated?
  • New dependencies (if any) added to requirements file

Reviewer guidance

  • Does the regression test make sense?

Issues addressed

closes #325

AI usage

The fix was pretty clear, but I let AI take the wheel. It wrote the regression test, then we verified the issue, then proceeded with the fix.

@bjester bjester requested review from ozer550 and rtibblesbot May 1, 2026 20:55
Copy link
Copy Markdown
Contributor

@rtibblesbot rtibblesbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, minimal fix for a nasty P0 edge case.

CI passing. No UI files changed — visual inspection skipped.

  • suggestion: release-v0.9.x has the same unfixed save method (confirmed by reading the branch). Since this is P0, a follow-up PR or backport to the default branch is worth tracking.
  • suggestion: (inline) consider a test for the update_dirty_bit_to=None + update_fields opt-out path
  • praise: (inline) the update_dirty_bit_to is not None guard correctly scopes the fix

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?

Reviewed the pull request diff checking for:

  • Correctness: bugs, edge cases, undocumented behavior, resource leaks, hardcoded values
  • Design: unnecessary complexity, naming, readability, comment accuracy, redundant state
  • Architecture: duplicated concerns, minimal interfaces, composition over inheritance
  • Testing: behavior-based assertions, mocks only at hard boundaries, accurate coverage
  • Completeness: missing dependencies, unupdated usages, i18n, accessibility, security
  • Principles: DRY (same reason to change), SRP, Rule of Three (no premature abstraction)
  • Checked CI status and linked issue acceptance criteria
  • For UI changes: inspected screenshots for layout, visual completeness, and consistency

Comment thread morango/models/core.py
self._morango_dirty_bit = False

# ensure the dirty bit field is in the fields to update if present, to keep it in sync
if update_dirty_bit_to is not None and kwargs.get("update_fields") is not None:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: The update_dirty_bit_to is not None guard correctly handles the opt-out case — callers who pass None to suppress all dirty-bit handling also suppress the update_fields injection, which is exactly right.


user.username = "updated-name"
user.save(update_fields=["username"])
self.assertTrue(MyUser.objects.first()._morango_dirty_bit)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: This test covers the common case well. Consider adding a second assertion for save(update_dirty_bit_to=None, update_fields=["username"]) to verify that the dirty bit is NOT updated in the DB when callers explicitly opt out — the fix handles it correctly, but a test would prevent regression if the guard condition is ever changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants