This is an automated email from the ASF dual-hosted git repository.
feluelle pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 1df83c5dff6 Type the ORM declarative base as a value of type Any
(#76025)
1df83c5dff6 is described below
commit 1df83c5dff61a031338bf3bc25c3a3a183acc4f6
Author: Felix Uellendall <[email protected]>
AuthorDate: Fri Oct 30 11:19:02 2026 +0100
Type the ORM declarative base as a value of type Any (#76025)
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.
---
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