This is an automated email from the ASF dual-hosted git repository.
vatsrahul1001 pushed a commit to branch v3-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v3-4-test by this push:
new b39d6785c92 [v3-4-test] Type the ORM declarative base as a value of
type Any (#76025) (#77780)
b39d6785c92 is described below
commit b39d6785c92d371a557acc5e0a1cc2b1744a8b18
Author: Rahul Vats <[email protected]>
AuthorDate: Mon Nov 30 16:29:52 2026 +0530
[v3-4-test] Type the ORM declarative base as a value of type Any (#76025)
(#77780)
Declaring Base as an alias of Any under TYPE_CHECKING makes ty (0.0.52+)
treat every model as an explicit Any subclass. Instances of those may be
None, so reading a Mapped column on a model instance resolves to
SQLAlchemy's class-access overload and is typed InstrumentedAttribute
instead of the column's value type, producing false positives for code
that type-checks against Airflow's models. A value of type Any keeps the
same meaning for mypy and pyright and avoids the explicit-Any semantics.
(cherry picked from commit 1df83c5dff61a031338bf3bc25c3a3a183acc4f6)
Co-authored-by: Felix Uellendall <[email protected]>
Co-authored-by: Claude <[email protected]>
---
airflow-core/src/airflow/models/base.py | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/airflow-core/src/airflow/models/base.py
b/airflow-core/src/airflow/models/base.py
index 522753f76ba..d9e6095bf8c 100644
--- a/airflow-core/src/airflow/models/base.py
+++ b/airflow-core/src/airflow/models/base.py
@@ -17,7 +17,7 @@
# under the License.
from __future__ import annotations
-from typing import TYPE_CHECKING, Any
+from typing import Any
from sqlalchemy import Integer, MetaData, String, event, text
from sqlalchemy.orm import Mapped, Mapper, mapped_column, registry
@@ -55,13 +55,10 @@ _sentinel = object()
# Mapper class (2.1 adds one per registry), so it fires on whichever registry
configures first.
event.listen(Mapper, "before_configured", import_all_models, once=True)
-if TYPE_CHECKING:
- Base = Any
-else:
- Base = mapper_registry.generate_base()
- # TEMPORARY workaround to allow using unmapped (v1.4) models in SQLAlchemy
2.0. It is intended only to
- # unblock the development of SQLA2 support.
- Base.__allow_unmapped__ = True
+Base: Any = mapper_registry.generate_base()
+# TEMPORARY workaround to allow using unmapped (v1.4) models in SQLAlchemy
2.0. It is intended only to
+# unblock the development of SQLA2 support.
+Base.__allow_unmapped__ = True
ID_LEN = 250