Repository navigation
fix(auth): silence authlib.jose DeprecationWarning at JWT import - #4100
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4206177e41
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
|
|
||
| from authlib.jose import JsonWebToken | ||
| from authlib.jose.errors import JoseError | ||
| from authlib.deprecate import AuthlibDeprecationWarning |
There was a problem hiding this comment.
Scope the Authlib warning filter import
When this is the first authlib.deprecate import in a process, Authlib 1.7 executes warnings.simplefilter("always", AuthlibDeprecationWarning) while importing this line. Because that happens before catch_warnings(), the context snapshots the already-mutated filters and restores the global always filter on exit; a caller that had set warnings.simplefilter("error", AuthlibDeprecationWarning) can import this module, but subsequent Authlib deprecations are no longer errors. Move this import inside the catch_warnings() block before installing the ignore filter so Authlib's filter mutation is restored too.
Useful? React with 👍 / 👎.
| import httpx | ||
| from authlib.jose import JsonWebKey, JsonWebToken | ||
| from authlib.jose.errors import JoseError | ||
| from authlib.deprecate import AuthlibDeprecationWarning |
There was a problem hiding this comment.
Scope the Authlib warning filter import
When this is the first authlib.deprecate import in a process, Authlib 1.7 executes warnings.simplefilter("always", AuthlibDeprecationWarning) while importing this line. Because that happens before catch_warnings(), the context snapshots the already-mutated filters and restores the global always filter on exit; a caller that had set warnings.simplefilter("error", AuthlibDeprecationWarning) can import this provider, but subsequent Authlib deprecations are no longer errors. Move this import inside the catch_warnings() block before installing the ignore filter so Authlib's filter mutation is restored too.
Useful? React with 👍 / 👎.
|
Good catch, pushed b1c0eef. |
|
tl;dr: The fix is a one-line whitespace change (a blank line after Log excerpt |
authlib.joseemitsAuthlibDeprecationWarningat module import time, so any caller running withwarnings.simplefilter("error")hits an exception just from touching FastMCP's JWT auth providers (from fastmcp.server.auth.providers.jwt import StaticTokenVerifieris enough to trigger it).Wraps the two
from authlib.jose ...imports inwarnings.catch_warnings()filteringAuthlibDeprecationWarning. The filter snapshot is restored on context exit, so this stays scoped to the one import site and doesn't leak into user code. Migrating offauthlib.josetojoserfcis a separate, larger change; this is the minimal patch for the warning.Closes #4098.