Skip to content

feat: tell conflicts apart by code - #258

Merged
uniqueg merged 4 commits into
devfrom
feat/conflict-codes
Oct 26, 2026
Merged

uniqueg merged 4 commits into
devfrom
feat/conflict-codes

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Every 409 Conflict now has a stable code member in its problem details, so clients can branch on it instead of on detail. The codes are:

  • duplicate-service
  • pending-service
  • unused-types-limit
  • service-type-registered
  • service-type-in-use
  • verification-mismatch
  • last-owner
  • conflict, for all other conflicts, e.g., from FOCA's permissions API

How it works:

  • Exceptions: conflicts that have their own code subclass the new CodedConflict (problem_code). problem() adds the code. Conflicts handled by FOCA get it from their mapping entry; FOCA's LastOwner maps to last-owner.
  • Spec: the new schema ConflictError (Error plus a required code) lists the codes as an x-extensible-enum, with a description of each. Generated clients therefore accept codes added later. All 409 responses use it.
  • Docs: docs/api.md > Errors has a table of the codes.
  • Tests: a test checks that the code, the spec and the docs table list the same codes. Each code is tested through the API.

Closes #247

Verification

  • Full suite on MongoDB 7.0.34 with coverage: 1275 passed, 228 skipped (Helm is not installed locally), 100% coverage.
  • Full suite on mongomock: 1273 passed, 230 skipped.
  • tests/test_conflicts.py and tests/test_access_control.py after the last commit: 77 passed.
  • ruff check, ruff format --check and mypy cloud_registry tests: clean.
  • mkdocs build --strict: OK.
  • pre-commit run --all-files: all passed.
  • Reviews: two rounds with the adversarial and quality reviewer subagents. Fixed:
    • schema renamed to ConflictError;
    • x-extensible-enum instead of a closed enum;
    • problem() falls back to mapping codes;
    • docs table checked by a test;
    • PUT cases for duplicates and the unused-types limit;
    • the duplicate code shared between both classes;
    • comments and imports.

Declined review findings

  • Module constants or a StrEnum for code strings: the test that compares the code with the spec and the docs catches typos and undocumented codes. The classes keep their codes next to their meaning.
  • Per-operation code lists in the spec: the codes are listed centrally in ConflictError, which names the operations of each code.
  • Conflicts that lose code when a deployment sets FOCA's exceptions.public_members: this repo doesn't set it. A deployment that filters members opts out of extension members by design.
  • POST /services/types reveals pending types of other users (service-type-registered): this behaviour existed before this PR (detail said the same). Out of scope here.
  • Coded conflicts that are raised instead of returned get conflict: none are raised uncaught today, and the CodedConflict docstring says to add a mapping entry for those.

Open questions

None.

🤖 Generated with Claude Code

Summary by Sourcery

Expose stable, documented codes for distinguishing API conflict responses.

New Features:

  • Add stable, extensible conflict codes to all 409 problem responses so clients can distinguish conflict causes without parsing details.

Enhancements:

  • Map application and FOCA conflicts, including last-owner errors, to consistent documented codes.

Documentation:

  • Document conflict codes and their meanings in the API specification and API guide.

Tests:

  • Add coverage for every conflict code and verify consistency between exception mappings, the OpenAPI schema, and documentation.

uniqueg and others added 3 commits October 26, 2026 14:39
Give every 409 Conflict a stable code member in its problem details
(duplicate-service, pending-service, unused-types-limit,
service-type-registered, service-type-in-use, verification-mismatch,
last-owner, conflict), so clients branch on it instead of on detail.

Conflicts with a code of their own subclass CodedConflict; all others,
also FOCA's, get the code conflict. FOCA's LastOwner is mapped to
last-owner. The spec documents the codes in the schema Conflict, and
a test checks that code and spec list the same codes.

Closes #247

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Rename the schema to ConflictError, apart from the response Conflict.
- List the codes as x-extensible-enum, so generated clients accept
  codes added later.
- problem() falls back to the code of the mapping entry (e.g.,
  last-owner); document both paths.
- Test updates, duplicates on PUT and the docs table of codes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

The PR makes 409 responses reliably machine-discriminable by adding stable conflict codes through coded exception subclasses and FOCA mappings, documenting them in an extensible OpenAPI schema and API guide, and testing every code plus cross-source consistency.

File-Level Changes

Change Details Files
Introduces stable, extensible codes for every 409 conflict and centralizes fallback and FOCA-specific mapping.
  • Adds CodedConflict with per-conflict problem codes and injects codes into problem details.
  • Maps generic conflicts to conflict and FOCA LastOwner errors to last-owner.
  • Assigns codes to duplicate, pending, unused-type-limit, service-type, and verification conflicts, preserving hidden duplicate behavior.
cloud_registry/exceptions.py
cloud_registry/ga4gh/registry/service.py
cloud_registry/ga4gh/registry/service_types.py
cloud_registry/ga4gh/registry/verification.py
Updates the API contract and documentation to expose conflict codes consistently while allowing future values.
  • Adds the ConflictError schema with a required code and x-extensible-enum values.
  • Changes all relevant 409 responses to reference ConflictError and clarifies operation-specific codes.
  • Documents code meanings, fallback handling, and forward compatibility for unknown codes.
cloud_registry/api/additions.openapi.yaml
docs/api.md
Adds comprehensive coverage for API behavior and consistency between implementation, specification, and documentation.
  • Tests each conflict code through representative POST, PUT, DELETE, and verification flows.
  • Verifies generic and mapped exception handling, hidden duplicate responses, and preserved problem extensions.
  • Checks that exception-defined codes, OpenAPI codes, and documentation table entries remain synchronized.
tests/test_conflicts.py
tests/test_access_control.py

Assessment against linked issues

Issue Objective Addressed Explanation
#247 Ensure every registry 409 problem response includes a stable discriminator that clients can use to distinguish conflict causes, without changing existing problem members. ✅
#247 Document the discriminator and supported conflict codes in the API specification and user-facing API documentation. ✅
#247 Add tests covering conflict codes and verifying that the documented codes stay consistent with the codes returned by the API. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (9ce0ef1) to head (2db6e4f).

Additional details and impacted files
@@            Coverage Diff            @@
##               dev      #258   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1734      1757   +23     
=========================================
+ Hits          1734      1757   +23     

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

@uniqueg
uniqueg marked this pull request as ready for review October 26, 2026 14:54

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="cloud_registry/exceptions.py" line_range="177" />
<code_context>
+            if isinstance(exc, CodedConflict)
+            else _mapped(exc).get("code", CONFLICT_CODE)
+        )
+        extensions = {"code": code, **extensions}
     return _response(
         title=_mapped(exc)["title"],
</code_context>
<issue_to_address>
**Clients see the wrong conflict reason**

When a caller passes `code` in `extensions` to `problem()`, `problem()` unpacks `extensions` after the derived `code`, so the caller-supplied value replaces the conflict’s stable code and clients see the wrong conflict reason.

Unpack `extensions` before setting the derived `code` so the stable code takes precedence.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: cloud_registry/exceptions.py:177


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread cloud_registry/exceptions.py Resolved

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

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit 79fd370 into dev Oct 26, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/conflict-codes branch October 26, 2026 15:14
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.

feat: tell 409 conflicts apart

1 participant