fix(typing): stop 3.14 DI wire NameError in MySQL session manager - #121
Merged
HosseinNejatiJavaremi merged 1 commit intoSep 13, 2026
Merged
HosseinNejatiJavaremi merged 1 commit into
HosseinNejatiJavaremi merged 1 commit into
Conversation
PEP 649 evaluates the TYPE_CHECKING-only PostgresUUID annotation on the visit_UUID patch that is installed on MySQLTypeCompiler, so inspect.signature() and container.wire() raise NameError. Stringify annotations, as 5.2.3 did for the other adapters and helpers.
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.
Description
Completes the Python 3.14 / PEP 649 annotation fix from 5.2.3 for the one module that release missed:
archipy/adapters/mysql/sqlalchemy/session_managers.py.The bug
On Python 3.14 (PEP 649), annotations are no longer evaluated at definition time; they compile into an
__annotate__function that does a real global name lookup the first time__annotations__is read.inspect.signature()reads it. Insession_managers.py,PostgresUUIDis imported only underif TYPE_CHECKING:but is used in the runtime-visible annotation of thevisit_UUIDfunction that the module monkeypatches onto SQLAlchemy'sMySQLTypeCompiler. The module has nofrom __future__ import annotations, so any signature inspection ofMySQLTypeCompiler.visit_UUIDraisesNameError: name 'PostgresUUID' is not defined.dependency_injector'scontainer.wire()callsinspect.signature()on every class member it finds in the wired modules, so this aborts wiring (and therefore service startup) whenever a wired namespace containsMySQLTypeCompiler. Because the patch is installed on SQLAlchemy's own class at import time, the broken annotation leaks to any other runtime introspection ofMySQLTypeCompilerin a process that imports the MySQL adapter.Relation to 5.2.3
5.2.3 (
352ff45b, "fix(typing): stop 3.14 DI wire NameError") fixed exactly this class of bug by addingfrom __future__ import annotationsacross errors, adapters, helpers, decorators, gRPC interceptors andFastAPIErrorResponseDTO. Its "SQLAlchemy" entry coversarchipy/adapters/base/sqlalchemy/{adapters,ports,session_manager_ports}.py. None of the dialect session managers were touched. Postgres and SQLite do not useTYPE_CHECKINGimports, and StarRocks already had the future import around an identicalvisit_UUIDpatch. The MySQL session manager was left behind.I ran a sweep that imports every
archipymodule (207 modules, all importable with all extras) and callsinspect.signature()on every function and class member defined in them:NameError)master(87140177)archipy.adapters.mysql.sqlalchemy.session_managers :: MySQLTypeCompiler.visit_UUID(NameError: name 'PostgresUUID' is not defined)Reproduction (Python 3.14.6, archipy 5.2.3)
Through
dependency_injector(4.x) on 5.2.3:The same happens with
wire(modules=[...])on thesession_managersmodule, on any app module that doesfrom sqlalchemy.dialects.mysql.base import MySQLTypeCompiler, and withwire(packages=[archipy]).The fix
One line, mirroring the 5.2.3 remedy and the StarRocks session manager next to it:
No other code changes.
Fixes # (no issue filed)
Type of change
How Has This Been Tested?
All on Python 3.14.6 with
uv sync --all-extras --all-groupsagainst the locked dependencies.features/atomic_transactions.feature(steps infeatures/steps/atomic_transaction_steps.py), modelled on the 5.2.3 "Public error constructors stay inspectable at runtime" scenario:archipy.adapters.<db_type>.sqlalchemy.session_managersand callsinspect.signatureon every function and class member in its namespace, which is the same walkcontainer.wire()performs. That includes the patchedMySQLTypeCompiler.visit_UUID.mysqlfails withMySQLTypeCompiler.visit_UUID: name 'PostgresUUID' is not defined, and postgres, sqlite and starrocks pass.atomic_transactions.featurehas feature-level@needs-postgres @needs-mysql @needs-starrockstags. The Postgres18.6-alpineand StarRocks all-in-one images could not be pulled in my environment, so I ran the new outline through behave from a temporary copy without those feature tags (same steps, not committed).behave --dry-run features/atomic_transactions.featureshows no undefined steps, and the untested count goes from 58 to 62 scenarios, as expected. I did not run the container-backed scenarios of that feature.dependency_injectorwiring ofarchipy.adapters.mysql.sqlalchemy.session_managers, and of a module importingMySQLTypeCompiler:NameErroron 5.2.3, wires cleanly on this branch.make format:208 files left unchangedmake lint: ruffAll checks passed!, tyAll checks passed!make security: no findings in the changed file (the only finding is a pre-existing medium elsewhere)uv run --extra behave behave features/error_handling.feature(includes the 5.2.3 inspectability scenario): 59 scenarios passed, 0 failedmake behave: not run, because the container images listed in.env.testwere not available in my environmentChecklist:
Additional context
Impact
MySQLTypeCompiler. Postgres, SQLite and StarRocks users are unaffected. In local checks, wiring app modules that only importMySQLSQLAlchemyAdapter,MySQLSQlAlchemySessionManagerormysql_sqlalchemy_atomic_decoratoralready worked on 5.2.3.visit_UUIDstill maps UUID toVARCHAR(36); only annotation evaluation becomes lazy (string).Changelog
Per
.cursor/rules/contributing.mdc, I have not editeddocs/community/changelog/because it is written at release time. Suggested entry in the 5.2.3 format: