SQLA: Replace the deprecated lazy="noload" with lazy="raise"#64262
Merged
Conversation
vincbeck
approved these changes
Mar 26, 2026
b9dc2bc to
f84b29a
Compare
802887c to
1c184d3
Compare
SQLAlchemy 2.1 deprecated the `noload` lazy loading strategy (sqlalchemy/sqlalchemy#11045). `noload` silently returns `None`/empty collections — essentially incorrect results — and will be removed in a future release. This PR replaces all 5 occurrences of `lazy="noload"` with `lazy="raise"`, which raises `InvalidRequestError` if the relationship is accessed without an explicit eager load (e.g. `joinedload`). All affected relationships are already properly loaded via `joinedload()` wherever they're accessed, so this is a safe drop-in that also catches missing eager loads at development time instead of silently returning `None`. Two callers needed fixes to work correctly with `lazy="raise"`: - `TaskInstance.rendered_task_instance_fields` and `TaskInstance.hitl_detail` needed `passive_deletes=True` to tell SQLAlchemy to rely on the DB-level `ON DELETE CASCADE` rather than attempting ORM-level cascade processing (which would fail since FK columns are also PK columns on RTIF, and `lazy="raise"` prevents the ORM from loading the collection to clear them). - The HITL API endpoints needed `joinedload(TI.rendered_task_instance_fields)` added to their queries, since `TaskInstanceResponse` accesses `rendered_task_instance_fields` during Pydantic serialization. The `get_hitl_detail` endpoint also needed an explicit `model_validate()` call so serialization happens while the session is still active. **Changed models:** - `Log.task_instance` - `TaskInstance.rendered_task_instance_fields` - `TaskInstance.hitl_detail` - `TaskInstanceHistory.hitl_detail` - `XComModel.task` related: apache#61229
1c184d3 to
7920321
Compare
jscheffl
approved these changes
Mar 28, 2026
jscheffl
approved these changes
Mar 28, 2026
nailo2c
pushed a commit
to nailo2c/airflow
that referenced
this pull request
Mar 30, 2026
…che#64262) SQLAlchemy 2.1 deprecated the `noload` lazy loading strategy (sqlalchemy/sqlalchemy#11045). `noload` silently returns `None`/empty collections — essentially incorrect results — and will be removed in a future release. This PR replaces all 5 occurrences of `lazy="noload"` with `lazy="raise"`, which raises `InvalidRequestError` if the relationship is accessed without an explicit eager load (e.g. `joinedload`). All affected relationships are already properly loaded via `joinedload()` wherever they're accessed, so this is a safe drop-in that also catches missing eager loads at development time instead of silently returning `None`. Two callers needed fixes to work correctly with `lazy="raise"`: - `TaskInstance.rendered_task_instance_fields` and `TaskInstance.hitl_detail` needed `passive_deletes=True` to tell SQLAlchemy to rely on the DB-level `ON DELETE CASCADE` rather than attempting ORM-level cascade processing (which would fail since FK columns are also PK columns on RTIF, and `lazy="raise"` prevents the ORM from loading the collection to clear them). - The HITL API endpoints needed `joinedload(TI.rendered_task_instance_fields)` added to their queries, since `TaskInstanceResponse` accesses `rendered_task_instance_fields` during Pydantic serialization. The `get_hitl_detail` endpoint also needed an explicit `model_validate()` call so serialization happens while the session is still active. **Changed models:** - `Log.task_instance` - `TaskInstance.rendered_task_instance_fields` - `TaskInstance.hitl_detail` - `TaskInstanceHistory.hitl_detail` - `XComModel.task` related: apache#61229
Suraj-kumar00
pushed a commit
to Suraj-kumar00/airflow
that referenced
this pull request
Apr 7, 2026
…che#64262) SQLAlchemy 2.1 deprecated the `noload` lazy loading strategy (sqlalchemy/sqlalchemy#11045). `noload` silently returns `None`/empty collections — essentially incorrect results — and will be removed in a future release. This PR replaces all 5 occurrences of `lazy="noload"` with `lazy="raise"`, which raises `InvalidRequestError` if the relationship is accessed without an explicit eager load (e.g. `joinedload`). All affected relationships are already properly loaded via `joinedload()` wherever they're accessed, so this is a safe drop-in that also catches missing eager loads at development time instead of silently returning `None`. Two callers needed fixes to work correctly with `lazy="raise"`: - `TaskInstance.rendered_task_instance_fields` and `TaskInstance.hitl_detail` needed `passive_deletes=True` to tell SQLAlchemy to rely on the DB-level `ON DELETE CASCADE` rather than attempting ORM-level cascade processing (which would fail since FK columns are also PK columns on RTIF, and `lazy="raise"` prevents the ORM from loading the collection to clear them). - The HITL API endpoints needed `joinedload(TI.rendered_task_instance_fields)` added to their queries, since `TaskInstanceResponse` accesses `rendered_task_instance_fields` during Pydantic serialization. The `get_hitl_detail` endpoint also needed an explicit `model_validate()` call so serialization happens while the session is still active. **Changed models:** - `Log.task_instance` - `TaskInstance.rendered_task_instance_fields` - `TaskInstance.hitl_detail` - `TaskInstanceHistory.hitl_detail` - `XComModel.task` related: apache#61229
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.
SQLAlchemy 2.1 deprecated the
noloadlazy loading strategy (sqlalchemy/sqlalchemy#11045).noloadsilently returnsNone/empty collections — essentially incorrect results — and will be removed in a future release.This PR replaces all 5 occurrences of
lazy="noload"withlazy="raise", which raisesInvalidRequestErrorif the relationship is accessed without an explicit eager load (e.g.joinedload). This is a safe drop-in that also catches missing eager loads at development time instead of silently returningNone.Changed models:
Log.task_instanceTaskInstance.rendered_task_instance_fieldsTaskInstance.hitl_detailTaskInstanceHistory.hitl_detailXComModel.taskAdditional fixes required by switching from
noloadtoraise:passive_deletes=TrueonTaskInstance.rendered_task_instance_fieldsandTaskInstance.hitl_detail: Withnoload, SQLAlchemy silently skipped ORM-level cascade processing. Withraise, it attempts ORM cascade which fails becauseRenderedTaskInstanceFieldsuses a composite PK (also the FK), so SQLAlchemy cannot null out FK columns during delete. Addingpassive_deletes=Truetells SQLAlchemy to defer to the DB-levelON DELETE CASCADEinstead.Eager-load
rendered_task_instance_fieldsin HITL endpoints: Theget_hitl_detailandget_hitl_detailsendpoints serialize aTaskInstanceResponsewhich accessesrendered_task_instance_fieldsvia a PydanticAliasPath. Withlazy="raise"this raised during serialization. Fixed by addingjoinedload(TI.rendered_task_instance_fields)to the query options, and returning an explicitly serialized Pydantic model fromget_hitl_detail(same pattern asupdate_hitl_detail).related: #61229
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Sonnet 4.6 following the guidelines