Skip to content

shared flow endpoints need to not be blocked by wrong locks - #179

Merged
pooleycodes merged 9 commits into
mainfrom
bug/preview-lock-both
Jul 28, 2026
Merged

shared flow endpoints need to not be blocked by wrong locks#179
pooleycodes merged 9 commits into
mainfrom
bug/preview-lock-both

Conversation

@pooleycodes

@pooleycodes pooleycodes commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

The entities preview is used by both add data and assign entities flows, however as it lives under add data, if you lock that process assign entities is unable to proceed.

Not a perfect solution, but RequestMeta now stores the source flow to check

Related Tickets & Documents

  • Ticket Link
  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Lock add-data process, and try to go all the way through assign entities, you should no longer be stopped.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above. Please refer to the Digital Land Testing Guidance for more information.

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

[optional] Are there any dependencies on other PRs or Work?

Summary by CodeRabbit

  • New Features

    • Shared preview and confirmation pages now apply the correct service lock based on whether the request belongs to Add Data or Assign Entities.
    • Requests now retain their originating workflow, improving handling across shared screens.
  • Bug Fixes

    • Add Data locks no longer block Assign Entities previews.
    • Assign Entities locks correctly prevent access to Assign Entities previews.
    • Add Data previews remain protected by Add Data locks.
  • Tests

    • Added coverage for workflow-specific access and locking behaviour.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pooleycodes, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 68fe3e27-c30f-4b62-8eae-107c50b67f1b

📥 Commits

Reviewing files that changed from the base of the PR and between 0412b76 and 26972c7.

📒 Files selected for processing (3)
  • application/blueprints/datamanager/router.py
  • docs/datamanager/architecture.md
  • tests/unit/blueprints/datamanager/controllers/test_add.py

Walkthrough

Request metadata now records whether previews originate from add-data or assign-entities flows. Shared datamanager endpoints use this value to apply the matching service lock, with updated preview handling, database migration, and acceptance coverage.

Changes

Flow-aware datamanager requests

Layer / File(s) Summary
Request metadata contract and writers
application/db/models.py, migrations/versions/..., application/blueprints/datamanager/controllers/request_meta.py, application/blueprints/datamanager/controllers/preview.py
RequestMeta gains nullable source_flow storage; metadata writers handle source-flow and branch-baseline persistence, while baseline logic is removed from preview.py.
Flow recording at preview submission
application/blueprints/datamanager/controllers/flagged_resources.py, application/blueprints/datamanager/controllers/form.py
Add-data and assign-entities submissions record their respective source flows after obtaining the preview ID.
Flow-aware preview and lock selection
application/blueprints/datamanager/controllers/preview.py, application/blueprints/datamanager/router.py
Entities-preview handling reads stored source-flow metadata, and shared endpoints select the corresponding service lock.
Lock behavior validation
tests/acceptance/blueprints/datamanager/test_flagged_resources.py, tests/unit/blueprints/datamanager/controllers/test_add.py
Tests cover lock isolation, flow-specific blocking, and assign-entities preview metadata.

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

Possibly related PRs

Suggested reviewers: gibahjoe

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: shared datamanager flow endpoints are no longer blocked by the wrong service lock.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug/preview-lock-both

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.

@pooleycodes pooleycodes changed the title shared flow endpoints need to not be blocked by locks shared flow endpoints need to not be blocked by wrong locks Jul 27, 2026
@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

📝 Documentation reminder

This PR changes 173 lines of code (threshold 100) but does not update anything in docs/. If this change affects behaviour, please update the relevant docs (e.g. docs/datamanager/).

This is a non-blocking reminder — it will not prevent merging.

@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.

🧹 Nitpick comments (2)
application/blueprints/datamanager/controllers/request_meta.py (1)

18-34: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

No validation constrains source_flow to its two known values.

Neither the write path nor the schema enforces source_flow ∈ {"add_data", "assign_entities"}. Since preview.py/router.py treat anything other than exactly "assign_entities" as "add_data", a typo or a future third flow would silently mis-select the process lock with no error surfaced.

  • application/blueprints/datamanager/controllers/request_meta.py#L18-L34: validate source_flow against the known literals in record_source_flow (raise or log on unexpected values) before persisting.
  • application/db/models.py#L27-L30: consider a CHECK constraint (via a follow-up migration) restricting source_flow to the same known values as defence-in-depth at the schema level.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@application/blueprints/datamanager/controllers/request_meta.py` around lines
18 - 34, Validate source_flow in record_source_flow against only "add_data" and
"assign_entities" before reading or persisting metadata, and raise or log an
unexpected value instead of silently treating it as add_data. Also add a
database CHECK constraint for RequestMeta.source_flow in
application/db/models.py covering the same two literals, with the corresponding
follow-up migration.
tests/acceptance/blueprints/datamanager/test_flagged_resources.py (1)

163-167: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

_seed_source_flow's use of merge() diverges from production's field-preserving update.

record_source_flow in production preserves other RequestMeta fields on update; this helper's merge() would null them out if reused against a row with pre-existing branch_sha/endpoints_to_retire. Not a problem for the current fresh-ID tests, but a trap if reused later.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/acceptance/blueprints/datamanager/test_flagged_resources.py` around
lines 163 - 167, Update _seed_source_flow to use the same field-preserving
source-flow update behavior as production’s record_source_flow instead of
merging a partial RequestMeta object. Ensure existing branch_sha and
endpoints_to_retire values remain unchanged while source_flow is recorded, then
preserve the existing commit behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@application/blueprints/datamanager/controllers/request_meta.py`:
- Around line 18-34: Validate source_flow in record_source_flow against only
"add_data" and "assign_entities" before reading or persisting metadata, and
raise or log an unexpected value instead of silently treating it as add_data.
Also add a database CHECK constraint for RequestMeta.source_flow in
application/db/models.py covering the same two literals, with the corresponding
follow-up migration.

In `@tests/acceptance/blueprints/datamanager/test_flagged_resources.py`:
- Around line 163-167: Update _seed_source_flow to use the same field-preserving
source-flow update behavior as production’s record_source_flow instead of
merging a partial RequestMeta object. Ensure existing branch_sha and
endpoints_to_retire values remain unchanged while source_flow is recorded, then
preserve the existing commit behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fee29ea6-2f0d-4d62-b9e3-15f9408bacd0

📥 Commits

Reviewing files that changed from the base of the PR and between 92507b4 and 0412b76.

📒 Files selected for processing (9)
  • application/blueprints/datamanager/controllers/flagged_resources.py
  • application/blueprints/datamanager/controllers/form.py
  • application/blueprints/datamanager/controllers/preview.py
  • application/blueprints/datamanager/controllers/request_meta.py
  • application/blueprints/datamanager/router.py
  • application/db/models.py
  • migrations/versions/b9c0d1e2f3a4_add_request_meta_source_flow.py
  • tests/acceptance/blueprints/datamanager/test_flagged_resources.py
  • tests/unit/blueprints/datamanager/controllers/test_add.py

@gibahjoe gibahjoe left a comment

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.

LGTM

@pooleycodes
pooleycodes merged commit 7a37886 into main Jul 28, 2026
7 checks passed
@pooleycodes
pooleycodes deleted the bug/preview-lock-both branch July 28, 2026 14:46
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