Repository navigation
Build the export path from a validated organization UUID - #95
Open
apoorvarohilla wants to merge 2 commits into
Open
apoorvarohilla wants to merge 2 commits into
apoorvarohilla wants to merge 2 commits into
Conversation
export_reviews is the only REST call whose path is formatted by hand, and it
interpolated organization_id without encoding. A non-UUID value could add
path segments, leave the organization through dot segments, or replace the
dataset through "?": export_reviews(f"{org}/exports/spend?x=", "reviews")
requested the spend export, and because both datasets are row version 1 the
page decoded as reviews without an error.
Convert organization_id to a UUID before building the path and raise
ValueError otherwise, before any request, as the method already does for an
unknown dataset or format. iter_export_pages inherits the check. Equivalent
UUID spellings still reach the canonical path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review feedback: ORG has no hex letters, so str(ORG).upper() equaled str(ORG) and the upper-case case repeated the string case. Use a UUID with hex letters, check that every spelling is a distinct input, and expect its canonical lower-case path. Also wrap EXPORT_WINDOW to the 100-column limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Problem
export_reviewsis the only REST call in the client whose path is built by hand, and it interpolatedorganization_idwithout encoding:f"/api/v1/organizations/{organization_id}/exports/{dataset}"Every generated operation encodes the organization as one path segment (
quote(str(org_id), safe="")), and the TypeScript SDK passes it as a typed path parameter, so this method was the outlier. Any value that is not a plain UUID changes which request is sent:export_reviews(UUID(org), "reviews")/api/v1/organizations/<org>/exports/reviewsexport_reviews("..", "reviews")/api/v1/exports/reviewsexport_reviews(f"{org}/../../reviews", "reviews")/api/v1/reviews/exports/reviewsexport_reviews(f"{org}/exports/spend?x=", "reviews")/api/v1/organizations/<org>/exports/spendThe last row is a silent wrong answer rather than an error. The caller asked for
reviews, the client fetchedspend, and because both datasets are row version 1,decode_export(..., "reviews")accepted the page. The caller received spend rows labeled as a reviews export.iter_export_pagesrepeats the same request on every page.A string organization ID is a plausible input: every other method accepts one and encodes it, and the MCP helpers document
organization_idas a UUID string.Approach
_export_pathconvertsorganization_idto aUUIDbefore building the path, and raisesValueErrorfor anything else before a request is made. The method already raisesValueErrorfor an unknowndatasetorformat, so a bad organization now fails the same way.iter_export_pagesgets the check throughexport_reviews.I chose rejection over percent-encoding because no non-UUID value can name an organization, and encoding
..would still leave a path that the URL resolves as a dot segment. Equivalent UUID spellings (string, upper case, braces, bare hex) are normalized to the canonical path, so existing callers that pass a UUID or its string keep working.Verification
Reproduction against a loopback server that answers each export path with that dataset's rows:
Tests (sync and async clients,
tests/test_http.py):test_export_refuses_an_organization_id_that_is_not_a_uuid: nine invalid values (..,., empty, slash,?,#, non-UUID text, an int,None) raiseValueErrorfrom bothexport_reviewsanditer_export_pages, and the server receives no request.test_export_sends_the_canonical_organization_path: aUUIDwith hex letters, its string, upper case, braced and bare upper-case hex spellings all reach the canonical lower-case/api/v1/organizations/<org>/exports/reviews.test_organization_spellings_are_distinctkeeps those five inputs distinct.Against
main, 24 of these 31 cases fail: all 18 refusal cases (each request is sent), and the upper-case, braced and hex spellings (sent as given instead of the canonical path). TheUUID, its string and the distinctness check pass. With this change all 31 pass, and the full suite:scripts/check.pydoes not run on Windows (#87), so I ran its ruff, mypy and pytest steps directly.Review feedback
I ran Proofline on this change in my fork. It flagged one warning: the test fixture
ORGhas no hex letters, sostr(ORG).upper()equaledstr(ORG)and the upper-case case repeated the string case. I confirmed it and switched the spelling test to a UUID with hex letters, with a check that the inputs stay distinct (29c65fb).Not changed
A UUID-typed argument passed as
".."to a generated operation is still resolved as a dot segment, for examplelist_repositories("..")requests/api/v1/repository-names. #84 handles the string coordinates of those operations; the UUID ones come from the generated templates, so I left them out of this hand-written fix.Prepared with AI assistance (Claude Code). I reviewed, ran and verified every change and test myself.