Repository navigation
feat: tell conflicts apart by code - #258
Merged
Merged
Conversation
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideThe 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
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
uniqueg
marked this pull request as ready for review
October 26, 2026 14:54
There was a problem hiding this comment.
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
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every
409 Conflictnow has a stablecodemember in its problem details, so clients can branch on it instead of ondetail. The codes are:duplicate-servicepending-serviceunused-types-limitservice-type-registeredservice-type-in-useverification-mismatchlast-ownerconflict, for all other conflicts, e.g., from FOCA's permissions APIHow it works:
CodedConflict(problem_code).problem()adds the code. Conflicts handled by FOCA get it from their mapping entry; FOCA'sLastOwnermaps tolast-owner.ConflictError(Error plus a requiredcode) lists the codes as anx-extensible-enum, with a description of each. Generated clients therefore accept codes added later. All 409 responses use it.docs/api.md> Errors has a table of the codes.Closes #247
Verification
tests/test_conflicts.pyandtests/test_access_control.pyafter the last commit: 77 passed.ruff check,ruff format --checkandmypy cloud_registry tests: clean.mkdocs build --strict: OK.pre-commit run --all-files: all passed.ConflictError;x-extensible-enuminstead of a closedenum;problem()falls back to mapping codes;Declined review findings
StrEnumfor 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.ConflictError, which names the operations of each code.codewhen a deployment sets FOCA'sexceptions.public_members: this repo doesn't set it. A deployment that filters members opts out of extension members by design.POST /services/typesreveals pending types of other users (service-type-registered): this behaviour existed before this PR (detailsaid the same). Out of scope here.conflict: none are raised uncaught today, and theCodedConflictdocstring 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:
Enhancements:
Documentation:
Tests: