-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Preserve empty issuer/resource paths on AuthSettings #2987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+41
−2
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 These two new tests add four new
# type: ignore[arg-type]comments, which AGENTS.md explicitly asks to avoid ("Avoid adding new # pragma: no cover, # type: ignore, or # noqa comments"). The same string-validation path can be exercised without the ignores viaAuthSettings.model_validate({"issuer_url": "https://as.example.com", "resource_server_url": "https://rs.example.com"}), matching the pattern already used in tests/client/test_auth.py for OAuthMetadata.Extended reasoning...
What the issue is
The two tests added in this PR (
test_auth_settings_preserves_path_less_issuerandtest_build_metadata_serves_issuer_without_trailing_slash) constructAuthSettingsby passing plain strings to theAnyHttpUrl-typedissuer_urlandresource_server_urlfields, suppressing the resulting type errors with four new# type: ignore[arg-type]comments (lines 54–55 and 64–65). AGENTS.md (Code Quality / Coverage section, ~line 100) explicitly says: "Avoid adding new# pragma: no cover,# type: ignore, or# noqacomments", and even provides the audit command maintainers run before pushing —git diff origin/main... | grep -E 'type: ignore'— which would flag exactly these four lines. These are also the only# type: ignore[arg-type]occurrences introduced into the tests tree by this PR.Why the tests are written this way (and why the ignores are still avoidable)
The tests genuinely need string input: passing an already-built
AnyHttpUrl("https://as.example.com")object would normalize the URL tohttps://as.example.com/at construction time, beforeurl_preserve_empty_path=Trueever applies, defeating the entire purpose of the test. So the string input is correct — but the constructor-with-ignore pattern is not the only way to get it.AuthSettings.model_validate({...})accepts a plain dict and runs the exact same Pydantic string-validation path, with no static type error and therefore no ignore needed.Existing precedent in the codebase
The repo already uses exactly this pattern for the same scenario:
tests/client/test_auth.py(around lines 2724–2734) usesOAuthMetadata.model_validate({...})with string URL values precisely to test theurl_preserve_empty_pathbehavior introduced in PR #2925, with a comment explaining it matches the wire path. Following that precedent here keeps the new tests consistent with the existing test for the sibling fix.Step-by-step proof that the alternative is equivalent
AuthSettings(issuer_url="https://as.example.com", ...)— Pydantic coerces the string throughAnyHttpUrlvalidation inside the model, whereurl_preserve_empty_path=Truefrommodel_configapplies, sostr(settings.issuer_url) == "https://as.example.com". The type checker complains because the declared type isAnyHttpUrl, hence the ignores.AuthSettings.model_validate({"issuer_url": "https://as.example.com", "resource_server_url": "https://rs.example.com"})— the dict values go through the identical field validation (string →AnyHttpUrlwith the model's config), producing the samesettingsobject and the same assertions passing.model_validateacceptsAny-typed input, so notype: ignoreis needed.build_metadatacall) is unchanged.How to fix
Replace the keyword-argument construction with
AuthSettings.model_validate({...})in both tests and drop the four# type: ignore[arg-type]comments. This is a minor, non-blocking convention issue — the tests are otherwise correct and valuable — so it's filed as a nit.