ashwiniadiga opened a new issue, #67923: URL: https://github.com/apache/airflow/issues/67923
### Under which category would you file this issue? Task SDK ### Apache Airflow version 3.2.2 ### What happened and how to reproduce it? In an Airflow multi-team setup (AIRFLOW__CORE__MULTI_TEAM = 'true'), the system is unable to access the team_a_retry_call_back connection during retry callback execution. However, the team_a_success_call_back and team_a_failure_call_back connections work correctly during their respective success and failure callbacks. This issue occurs because retry tasks are moved from the TaskInstance table to the TaskInstanceHistory table during retries, and the current team_name resolution logic (get_team_name_dep) fails to query the TaskInstanceHistory table. As a result, retry callbacks cannot resolve the team_name, leading to failures when accessing team-specific connections and configurations. -------------------------------------------------------------------------------------------------------------- <h3 style="margin: 1.5rem 0px 0px; padding: 0px; color: rgb(36, 36, 36); font-size: 14px; line-height: 24px; font-weight: 600; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Steps to Reproduce:</h3><h4 style="margin: 1.5rem 0px 0px; padding: 0px; color: rgb(36, 36, 36); font-size: 14px; line-height: 22px; font-weight: 600; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Prerequisites:</h4><ol style="margin: 1.5rem 0px 0px; padding: 0px 0px 0px 2em; color: rgb(66, 66, 66); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="margin: 0px; padding: 0px;">Ensure<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">AIRFLOW__CORE__MULTI_TEAM</code><span> </span>is set to<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">'true'</code><span> </span>in the Airflow configuration.</li><li style="margin: 0px; padding: 0px;">Define a<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">dag_bundle_config_list</code><span> </span>to segregate DAGs by teams:<pre style="margin: 0px; padding: 0px;"><button type="button" class="fui-Button r1alrhcs codeCopyBtn ___w3o4yv0 fhovq9v f1p3nwhy f11589ue f1q5o8ev f1pdflbu fkfq4zb f1t94bn6 f1s2uweq fr80ssc f1ukrpxl fecsdlb fnwyq0v ft1hn21 fuxngvv fy5bs14 fsv2rcd f1h0usnq fs4ktlq f16h9ulv fx2bmrt f1omzyqd f1dfjoow f1j98vj9 fj8 yq94 f4xjyn1 f1et0tmh f9ddjv3 f1wi8ngl f18ktai2 fwbmr0d f44c6la" style="align-items: center; box-sizing: border-box; display: inline-flex; justify-content: center; text-decoration-line: none; vertical-align: middle; margin: 0px; overflow: hidden; background-color: rgba(0, 0, 0, 0); color: rgb(66, 66, 66); border-color: transparent; border-style: solid; border-width: 1px; border-image: none 100% / 1 / 0 stretch; font-family: inherit; outline-style: none; padding: 0px; min-width: 32px; border-radius: 4px; font-size: 14px; font-weight: 600; line-height: 20px; transition-duration: 0.1s; transition-property: background, border, color; transition-timing-function: cubic-bezier(0.33, 0, 0.67, 1); max-width: 32px;"><span class="fui-Button__icon rywnvv2" style="align-items: center; display: inline-flex; justify-content: center; font-size: 20px; height: 20px; width: 20px; --fui-Button__icon--spacing: 6px; margin: 0px; padding: 0px;"><svg fill="currentColor" class="___12fm75w f1w7gpdv fez10in f g4l7m0" aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M8 2a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h6a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8ZM7 4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V4ZM4 6a2 2 0 0 1 1-1.73V14.5A2.5 2.5 0 0 0 7.5 17h6.23A2 2 0 0 1 12 18H7.5A3.5 3.5 0 0 1 4 14.5V6Z" fill="currentColor"></path></svg></span></button><div style="margin: 0px; padding: 0.5em; display: block; overflow-x: auto; background: rgb(43, 43, 43); color: rgb(248, 248, 242);"><code class="language-javascript" style="margin: 0px; padding: 0px; white-space: pre-wrap;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;">dag_bundle_config_list = [ </span></span><span style="margin: 0px; padding: 0px;"> { </span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"name"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_a_dags"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"classpath"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"airflow.dag_processing.bundles.local.LocalDagBundle"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"kwargs"</span><span style="margin: 0px; padding: 0px;">: {</span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"path"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"/opt/airflow/dags/team_a"</span><span style="margin: 0px; padding: 0px;">}, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_name"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_a"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"> }, </span><span style="margin: 0px; padding: 0px;"> { </span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"name"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_b_dags"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"classpath"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"airflow.dag_processing.bundles.local.LocalDagBundle"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"kwargs"</span><span style="margin: 0px; padding: 0px;">: {</span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"path"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"/opt/airflow/dags/team_b"</span><span style="margin: 0px; padding: 0px;">}, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_name"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"team_b"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"> }, </span><span style="margin: 0px; padding: 0px;"> { </span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"name"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"shared_dags"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"classpath"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"airflow.dag_processing.bundles.local.LocalDagBundle"</span><span style="margin: 0px; padding: 0px;">, </span></span><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;"> </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"kwargs"</span><span style="margin: 0px; padding: 0px;">: {</span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"path"</span><span style="margin: 0px; padding: 0px;">: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">"/opt/airflow/dags/shared"</span><span style="margin: 0px; padding: 0px;">}, </span></span><span style="margin: 0px; padding: 0px;"> }, </span><span style="margin: 0px; padding: 0px;">] </span></code></div></pre></li></ol><h4 style="margin: 1.5rem 0px 0px; padding: 0px; color: rgb(36, 36, 36); font-size: 14px; line-height: 22px; font-weight: 600; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Connection Setup:</h4><p style="margin: 1.5rem 0px 0px; padding: 0px; line-height: 20px; color: rgb(66, 66, 66); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Ensure the following connections are scoped to<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a</code>:</p> Connection ID | Type | Host | Description | Team Name -- | -- | -- | -- | -- team_a_failure_call_back | http | team_a_failure_call_back | Failure callback connection | team_a team_a_retry_call_back | http | team_a_retry_call_back | Retry callback connection | team_a team_a_success_call_back | http | (empty) | Success callback connection | team_a <h4 style="margin: 1.5rem 0px 0px; padding: 0px; color: rgb(36, 36, 36); font-size: 14px; line-height: 22px; font-weight: 600; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Steps:</h4><ol style="margin: 1.5rem 0px 0px; padding: 0px 0px 0px 2em; color: rgb(66, 66, 66); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-si ze: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="margin: 0px; padding: 0px;">Create a DAG for<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a</code><span> </span>with the following tasks:<ul style="margin: 0px; padding: 0px 0px 0px 2em;"><li style="margin: 0px; padding: 0px;"><strong style="margin: 0px; padding: 0px;">Success Task (<code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">success_task</code>)</strong>: Uses a success callback with the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a_success_call_back</code> <span> </span>connection.</li><li style="margin: 0px; padding: 0px;"><strong style="margin: 0px; padding: 0px;">Failure Task (<code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">failure_task</code>)</strong>: Uses a failure callback with the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a_failure_call_back</code><span> </span>connection.</li><li style="margin: 0px; padding: 0px;"><strong style="margin: 0px; padding: 0px;">Retry Task (<code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">retry_task</code>)</strong>: Uses a retry callback with the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a_retry_call_back</code><span> </span>connection.</li></ul></li><li style="margin: 0px; padding: 0px;">Execute the DAG:<ul style="margin: 0px; padding: 0px 0px 0px 2em;"><li style="margin: 0px; padding: 0px;">Allow the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180); ">success_task</code><span> </span>to succeed and trigger its success callback.</li><li style="margin: 0px; padding: 0px;">Force the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">failure_task</code><span> </span>to fail immediately and trigger its failure callback.</li><li style="margin: 0px; padding: 0px;">Allow the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">retry_task</code><span> </span>to fail and retry, triggering its retry callback.</li></ul></li><li style="margin: 0px; padding: 0px;">Observe the behavior during retries for<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">retry_task</code>.</li></ol><hr style="margin: 1.5rem 0px 0px; padding: 0px; border-top: 1px solid rgb(224, 224, 224); border-right: none; border-bottom: none; border-left: none; border-image: initial; margin-block: 1.5rem; font-family: "Segoe UI", "Segoe UI Web (West European)", "Seg oe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><h3 style="margin: 1.5rem 0px 0px; padding: 0px; color: rgb(36, 36, 36); font-size: 14px; line-height: 24px; font-weight: 600; font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text- transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;">Observed Behavior:</h3><ul style="margin: 1.5rem 0px 0px; padding: 0px 0px 0px 2em; color: rgb(66, 66, 66); font-family: "Segoe UI", "Segoe UI Web (West European)", "Segoe UI", -apple-system, "system-ui", Roboto, "Helvetica Neue", sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><li style="margin: 0px; padding: 0p x;">The success callback correctly accesses the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a_success_call_back</code><span> </span>connection.</li><li style="margin: 0px; padding: 0px;">The failure callback correctly accesses the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_a_failure_call_back</code><span> </span>connection.</li><li style="margin: 0px; padding: 0px;">The retry callback fails with the following error:<pre style="margin: 0px; padding: 0px;"><button type="button" class="fui-Button r1alrhcs codeCopyBtn ___w3o4yv0 fhovq9v f1p3nwhy f11589ue f1q5o8ev f1pdflbu fkfq4zb f1t94bn6 f1s2uweq fr80ssc f1ukrpxl fecsdlb fnwyq0v ft1hn21 fuxngvv fy5bs14 fsv2rcd f1h0usnq fs4ktlq f16h9ulv fx2bmrt f1omzyqd f1dfjoow f1j98vj9 fj8yq94 f4xjyn1 f1et0tmh f9ddjv3 f1wi8ngl f18ktai2 fwbmr0d f44c6la" style="align-items: center; box-sizing: border-box; display: inline-flex; justify-content: center; text-decoration-line : none; vertical-align: middle; margin: 0px; overflow: hidden; background-color: rgba(0, 0, 0, 0); color: rgb(66, 66, 66); border-color: transparent; border-style: solid; border-width: 1px; border-image: none 100% / 1 / 0 stretch; font-family: inherit; outline-style: none; padding: 0px; min-width: 32px; border-radius: 4px; font-size: 14px; font-weight: 600; line-height: 20px; transition-duration: 0.1s; transition-property: background, border, color; transition-timing-function: cubic-bezier(0.33, 0, 0.67, 1); max-width: 32px;"><span class="fui-Button__icon rywnvv2" style="align-items: center; display: inline-flex; justify-content: center; font-size: 20px; height: 20px; width: 20px; --fui-Button__icon--spacing: 6px; margin: 0px; padding: 0px;"><svg fill="currentColor" class="___12fm75w f1w7gpdv fez10in fg4l7m0" aria-hidden="true" width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M8 2a2 2 0 0 0-2 2v10c0 1.1.9 2 2 2h6a2 2 0 0 0 2-2V4a2 2 0 0 0-2-2H8Z M7 4a1 1 0 0 1 1-1h6a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H8a1 1 0 0 1-1-1V4ZM4 6a2 2 0 0 1 1-1.73V14.5A2.5 2.5 0 0 0 7.5 17h6.23A2 2 0 0 1 12 18H7.5A3.5 3.5 0 0 1 4 14.5V6Z" fill="currentColor"></path></svg></span></button><div style="margin: 0px; padding: 0.5em; display: block; overflow-x: auto; background: rgb(43, 43, 43); color: rgb(248, 248, 242);"><code class="language-javascript" style="margin: 0px; padding: 0px; white-space: pre-wrap;"><span style="margin: 0px; padding: 0px;"><span style="margin: 0px; padding: 0px;">KeyError: </span><span style="margin: 0px; padding: 0px; color: rgb(171, 227, 56);">'Connection team_a_retry_call_back not found in secrets backend'</span><span style="margin: 0px; padding: 0px;"> </span></span></code></div></pre></li><li style="margin: 0px; padding: 0px;">The issue occurs because the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">get_team_name_dep</code><span> </span>logic fails to resolve the<span> </span><code style ="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">team_name</code><span> </span>for tasks moved to the<span> </span><code style="margin: 0px; padding: 0px; color: rgb(0, 39, 180);">TaskInstanceHistory</code><span> </span>table during retries.</li></ul> ### What you think should happen instead? Expected Behavior: The team_name should be resolved correctly during retries, even if the task has been moved to the TaskInstanceHistory table. The retry callback should successfully access the team_a_retry_call_back connection. ------------------------------------------------------- Root Cause: The get_team_name_dep logic only queries the TaskInstance table to resolve the team_name. When tasks are moved to the TaskInstanceHistory table during retries, they become inaccessible to the current query, resulting in a failure to resolve the team_name and access the necessary connections. Suggested Fix: Update get_team_name_dep Logic: Modify the get_team_name_dep function in airflow-core/src/airflow/api_fastapi/execution_api/security.py to query both the TaskInstance and TaskInstanceHistory tables. If a team_name is not found in the TaskInstance table, the function should fall back to the TaskInstanceHistory table. Code Update: from sqlalchemy import union_all def get_team_name_dep(token): # Query the TaskInstance table stmt = ( select(Team.name) .select_from(TaskInstance) .join(DagModel, DagModel.dag_id == TaskInstance.dag_id) .join(DagBundleModel, DagBundleModel.name == DagModel.bundle_name) .join(DagBundleModel.teams) .where(TaskInstance.id == token.id) ) # Query the TaskInstanceHistory table stmt_history = ( select(Team.name) .select_from(TaskInstanceHistory) .join(DagModel, DagModel.dag_id == TaskInstanceHistory.dag_id) .join(DagBundleModel, DagBundleModel.name == DagModel.bundle_name) .join(DagBundleModel.teams) .where(TaskInstanceHistory.task_instance_id == token.id) ) # Combine both queries with UNION ALL combined_stmt = union_all(stmt, stmt_history) # Return the first valid result return select(Team.name).from_statement(combined_stmt).limit(1) ### Operating System _No response_ ### Deployment Docker-Compose ### Apache Airflow Provider(s) _No response_ ### Versions of Apache Airflow Providers _No response_ ### Official Helm Chart version Not Applicable ### Kubernetes Version _No response_ ### Helm Chart configuration _No response_ ### Docker Image customizations NA ### Anything else? _No response_ ### Are you willing to submit PR? - [x] Yes I am willing to submit a PR! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
