You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "guan404ming (via GitHub)" <gi...@apache.org> on 2025/09/02 02:16:12 UTC
[PR] Alias `task_display_name` for `EventLogResponse` [airflow]
guan404ming opened a new pull request, #55160:
URL: https://github.com/apache/airflow/pull/55160
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
## Related Issue
#46730
## How
- alias the `task_display_name` for `EventLogResponse`
- update related tests
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2315588677
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
I think it might be null. Since `dag_id` and `task_id`can also be `None` here, it means the relationships to `dag_model` and `task_instance` can be `None`, which indicates that `display_name` is possible to be `None`.
However, when they do exist, the display names should always be never `None` as confirmed by the hybrid property logic like what you said.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2314846983
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ lazy="selectin",
Review Comment:
Any specific reason behind this lazy strat?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2359653959
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
Yes no load seems like a safer option. Forcing the users to eagerly request the option loading if required.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #55160:
URL: https://github.com/apache/airflow/pull/55160
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #55160:
URL: https://github.com/apache/airflow/pull/55160#issuecomment-3254067013
Feel free to resolve comments when they are address so we can merge it @guan404ming (unless there is more work planned here)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on PR #55160:
URL: https://github.com/apache/airflow/pull/55160#issuecomment-3254556387
> Feel free to resolve comments when they are address so we can merge it @guan404ming (unless there is more work planned here)
Sure, let me resolve them. It's currently looks good for me but if TP still have any questions please feel free to let me know. I could help follow up or clarify. Thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2316769071
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,13 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ )
+
Review Comment:
So ideally the usage priority would be:
1. If `SQLAlchemy` can auto-detect the relationship -> only specify lazy="selectin"
2. If `SQLAlchemy` cannot auto-detect -> specify foreign_keys and primaryjoin explicitly
I think this follows the principle of minimal configuration to only add explicit relationship parameters when absolutely necessary for `SQLAlchemy` to understand the join.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2353160376
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
Thanks for the feedback!
I’d prefer not to remove the relationship because it’s useful to keep it defined at the model level — it makes the schema explicit, provides type hints/IDE support, and simplifies queries where we actually need to join TaskInstance.
To avoid the side effect of preloading TIs for every Log query (like in the scheduler), I think we could switch to lazy="noload". That way the relationship is still available for use, but it won’t be auto-loaded unless explicitly requested (e.g., in the get_logs endpoint with .options(...)). Would that address the concern?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2316761972
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,13 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ )
+
Review Comment:
> We have discussed the usage of relationship before at https://github.com/apache/airflow/pull/54820#pullrequestreview-3144771835. Does this mean it depends on the model in each case, rather than having all relationship definitions be the same?
Sorry for not explain the inconsistent.
The key difference is that `DagWarning` has a simple, single-column foreign key relationship where `DagWarning.dag_id` directly references `DagModel.dag_id` with the same column name, allowing SQLAlchemy to automatically infer the join condition.
Log's relationship to TaskInstance is more complex - it needs to join on `Log.task_id = TaskInstance.task_id`, but SQLAlchemy cannot automatically determine this relationship because there's no explicit foreign key constraint and the join logic isn't obvious from the table structure alone.
Thus, I think Log requires explicit `foreign_keys` and `primaryjoin` parameters to tell SQLAlchemy exactly how to perform the join.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2317673010
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,13 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ )
+
Review Comment:
I see, thanks for the clear explanation and it seems reasonable to me. The guideline you proposed LGTM, thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2353160376
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
Thanks for the feedback!
I’d prefer not to remove the relationship because it’s useful to keep it defined at the model level — it makes the schema explicit, provides type hints/IDE support, and simplifies queries where we actually need to join TaskInstance.
To avoid the side effect of preloading TIs for every Log query (like in the scheduler), I think we could switch to `lazy="noload"`. That way the relationship is still available for use, but it won’t be auto-loaded unless explicitly requested (e.g., in the get_logs endpoint with .options(...)). Would that address the concern?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2338142274
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
Review Comment:
CF my comment above for lazily emitting db queries.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2315588677
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
I think it might be null. Since `dag_id` and `task_id`can also be `None` here, it means the relationships to `dag_model` and `task_instance` can be `None`, which indicates that `display_name` is possible to be `None`.
However, when they do exist, the display names should always be never `None` as confirmed by the hybrid property logic like what you said. Please let me know if I've misunderstood anything, thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2315588677
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
I think it might be null. Since `dag_id` and `task_id`can also be `None` here, it means the relationships to `dag_model` and `task_instance` can be both `None`, which indicates that `display_name` is possible to be `None`.
However, when they do exist, the display names should always be never `None` as confirmed by the hybrid property logic like what you said. Please let me know if I've misunderstood anything, thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2353690743
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
I agree with both Pierre and Guan-Ming, setting `lazy="noload"` LGTM.
If everyone agrees on using `lazy="noload"`, let's also review previous PRs where aliases were added. We should ensure those relationships are set to `lazy="noload"` to avoid performance side effect, while still benefiting from easier queries and IDE type hints.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2348359860
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
We shouldn't add this to the model. Because this will impact and preload `TI` for all requests on `Log`. Even if this is not necessary, for instance the scheduler is querying this table, and it will start emitting additional queries to load that relationship.
We should instead to that only on the `apiserver` part in the `get_logs` endpoint basically. `.options(...)` to the Log query there.
This will help preventing unexpected side effects.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2314846386
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
I don’t think this can ever be None? TaskInstance always defaults to task_id if the column does not contain a value.
Actually dag_display_name also cannot be None as far as I can tell. Maybe we should fix it too.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2316026777
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
If I get the context correctly, there are the cases where `dag_id` and `task_id` both will be `None`.
Take `delete_asset_queued_events` route as example:
https://github.com/apache/airflow/blob/c29696cf2888e858551e7b782c94f66564abeeb2/airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py#L554-L563
We can't get either `dag_id` or `task_id` from the query params and path params.
https://github.com/apache/airflow/blob/c29696cf2888e858551e7b782c94f66564abeeb2/airflow-core/src/airflow/api_fastapi/logging/decorators.py#L140-L150
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,13 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ )
+
Review Comment:
We have discussed the usage of `relationship` before at https://github.com/apache/airflow/pull/54820#pullrequestreview-3144771835. Does this mean it depends on the model in each case, rather than having all `relationship` definitions be the same?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2316026777
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
+ validation_alias=AliasPath("task_instance", "task_display_name"), default=None
+ )
Review Comment:
If I get the context correctly, there will be the cases where `dag_id` and `task_id` both will be `None`.
Take `delete_asset_queued_events` route as example:
https://github.com/apache/airflow/blob/c29696cf2888e858551e7b782c94f66564abeeb2/airflow-core/src/airflow/api_fastapi/core_api/routes/public/assets.py#L554-L563
We can't get either `dag_id` or `task_id` from the query params and path params.
https://github.com/apache/airflow/blob/c29696cf2888e858551e7b782c94f66564abeeb2/airflow-core/src/airflow/api_fastapi/logging/decorators.py#L140-L150
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2315600230
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ lazy="selectin",
Review Comment:
I put it for prevent N+1 queries but it seems redundant here. Let me remove it. Thanks for catching this.
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ lazy="selectin",
Review Comment:
I put it for preventing N+1 queries but it seems redundant here. Let me remove it. Thanks for catching this.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #55160:
URL: https://github.com/apache/airflow/pull/55160#issuecomment-3472314970
Manual backport https://github.com/apache/airflow/pull/57609
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2342929011
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/event_logs.py:
##########
@@ -41,6 +41,9 @@ class EventLogResponse(BaseModel):
dag_display_name: str | None = Field(
validation_alias=AliasPath("dag_model", "dag_display_name"), default=None
)
+ task_display_name: str | None = Field(
Review Comment:
Thanks for catching this. I've updated to correct version.
After reviewing in more detail, I think Pierre is right. We still need to explicitly specify `lazy="selectin"`, since the default is `lazy="select"` (see [SQLAlchemy source](https://github.com/sqlalchemy/sqlalchemy/blob/adabce3aa6ce25e785762b5a28a294e9112b03b5/lib/sqlalchemy/orm/_orm_constructors.py#L1465)). I had misunderstood and thought it would default to "selectin" when primaryjoin is defined.
So ideally the updated usage for alias related cases would be:
- If SQLAlchemy can auto-detect the relationship -> only specify `lazy="selectin"`
- If SQLAlchemy cannot auto-detect -> specify foreign_keys and primaryjoin explicitly + specify `lazy="selectin"`
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Alias `task_display_name` for `EventLogResponse` [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #55160:
URL: https://github.com/apache/airflow/pull/55160#discussion_r2348359860
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
We shouldn't add this to the model. Because this will impact and preload `TI` for all requests on `Log`, even if this is not necessary. For instance the scheduler is querying this table, and it will start emitting additional queries to load that relationship.
We should instead to that only on the `apiserver` part in the `get_logs` endpoint basically. `.options(...)` to the Log query there.
This will help preventing unexpected side effects.
##########
airflow-core/src/airflow/models/log.py:
##########
@@ -56,6 +56,14 @@ class Log(Base):
primaryjoin="Log.dag_id == DagModel.dag_id",
)
+ task_instance = relationship(
+ "TaskInstance",
+ viewonly=True,
+ foreign_keys=[task_id],
+ primaryjoin="Log.task_id == TaskInstance.task_id",
+ lazy="selectin",
+ )
+
Review Comment:
We shouldn't add this to the model. Because this will impact and preload `TI` for all requests on `Log`, even if this is not necessary. For instance the scheduler is querying this table, and it will start emitting additional queries to load that relationship.
We should instead do that only on the `apiserver` part in the `get_logs` endpoint basically. `.options(...)` to the Log query there.
This will help preventing unexpected side effects.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org