Skip to content

fix(versioning): block manual commit of a stale change request - #8219

Open
bardock-2393 wants to merge 3 commits into
Flagsmith:mainfrom
bardock-2393:fix/cr-manual-commit-conflict-check
Open

fix(versioning): block manual commit of a stale change request#8219
bardock-2393 wants to merge 3 commits into
Flagsmith:mainfrom
bardock-2393:fix/cr-manual-commit-conflict-check

Conversation

@bardock-2393

Copy link
Copy Markdown
Contributor

Changes

Manually committing a Change Request skipped the conflict check that scheduled publishes already run, so a CR whose captured overrides had since been changed and published by another CR could still be committed — silently reverting the newer change back to the stale captured values, with only a passive "published since" notice.

This reuses the existing VersionChangeSet.get_conflicts() check (already used by scheduled publishes) on the manual commit path too. A stale commit is now rejected with a 400 (ChangeRequestStaleError) instead of silently overwriting, unless the CR has ignore_conflicts set — the same opt-out scheduled publishes already respect.

Closes #7931

How did you test this code?

Added test_change_request_commit__stale_change_set__raises_exception_and_does_not_revert_conflicting_change and test_change_request_commit__stale_change_set_but_ignore_conflicts__commits_and_reverts_change to test_unit_workflows_models.py, reproducing the issue's exact scenario. Verified both fail against the old code and pass against the fix. Ran the full test_unit_workflows_models.py + features/versioning + core suites (198 passed). Ran mypy and the project's pre-commit hooks, all clean.

Note: the HTTP endpoint that calls .commit() lives in the closed-source workflows_logic module, so this was verified at the service/model layer; I couldn't add an end-to-end API test for it from this repo.

Review effort: 3/5

A Change Request commit skipped the conflict check that scheduled
publishes already run, so committing a CR whose captured overrides
had since been changed by another published CR would silently
overwrite that newer change. Run the same VersionChangeSet conflict
check on manual commits and reject them with ChangeRequestStaleError
unless ignore_conflicts is set, consistent with scheduled publishes.
@bardock-2393
bardock-2393 requested review from a team as code owners August 5, 2026 11:55
@bardock-2393
bardock-2393 requested review from khvn26 and removed request for a team August 5, 2026 11:55
@vercel

vercel Bot commented Aug 5, 2026

Copy link
Copy Markdown

@bardock-2393 is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4d525645-071f-498c-b0b0-d7b853129e84

📥 Commits

Reviewing files that changed from the base of the PR and between 86ee5cd and 1024a48.

📒 Files selected for processing (1)
  • api/tests/unit/features/workflows/core/test_unit_workflows_models.py

📝 Walkthrough

Walkthrough

The commit workflow now detects stale change sets before publishing. It raises ChangeRequestStaleError unless ignore_conflicts=True. New tests cover rejection and forced overwrite behaviour. The observability catalogue documents the stale warning event and updates source locations for related workflow events.

Estimated code review effort: 3 (Moderate) | ~20 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added api Issue related to the REST API docs Documentation updates labels Aug 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 98429da5-3b78-4bdb-864e-9d80314bfbbb

📥 Commits

Reviewing files that changed from the base of the PR and between fb78687 and 6b53f40.

📒 Files selected for processing (4)
  • api/core/workflows_services.py
  • api/features/workflows/core/exceptions.py
  • api/tests/unit/features/workflows/core/test_unit_workflows_models.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md

Comment thread api/tests/unit/features/workflows/core/test_unit_workflows_models.py Outdated
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.59%. Comparing base (6c88198) to head (1024a48).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8219      +/-   ##
==========================================
- Coverage   98.73%   98.59%   -0.15%     
==========================================
  Files        1567     1567              
  Lines       62379    62413      +34     
==========================================
- Hits        61591    61535      -56     
- Misses        788      878      +90     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…setup

Addresses review feedback on the stale change request tests: the
`ignore_conflicts` test asserted only that the commit happened, not that
CR A's captured state actually overwrote CR B's published change, so a
regression that skipped the publish would still pass.

The shared setup for both tests is now built by a single helper.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
api/core/workflows_services.py (1)

37-42: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Make conflict detection atomic with publication.

commit() checks conflicts before _publish_change_sets(). No shared transaction or lock covers these operations, and scheduled publication performs its conflict check separately. Concurrent commits can both pass the check and publish overlapping changes, allowing stale state to become current.

Use a common lock or an atomic compare-and-set. Perform the conflict check and publication in the same critical section, including publish_version_change_set() for scheduled changes. Add a concurrent regression test.

Source: Learnings

api/features/workflows/core/exceptions.py (1)

29-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the mypy suppression.

The # type: ignore[assignment] code is precise, but the comment does not state why the Django REST framework status constant requires suppression. Add a short reason, or remove the suppression if the repository's current typing accepts the assignment.

Based on learnings: API type suppressions should include a short explanation of the external typing limitation.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: e0e5857e-5461-4483-965e-a8a59f96ea80

📥 Commits

Reviewing files that changed from the base of the PR and between 6b53f40 and 86ee5cd.

📒 Files selected for processing (4)
  • api/core/workflows_services.py
  • api/features/workflows/core/exceptions.py
  • api/tests/unit/features/workflows/core/test_unit_workflows_models.py
  • docs/docs/deployment-self-hosting/observability/_events-catalogue.md

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

Labels

api Issue related to the REST API docs Documentation updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change Requests can silently overwrite concurrent changes on commit

1 participant