SameerMesiah97 commented on code in PR #70772:
URL: https://github.com/apache/airflow/pull/70772#discussion_r3683252209
##########
providers/openlineage/src/airflow/providers/openlineage/utils/utils.py:
##########
@@ -1073,18 +1080,27 @@ def team_name(cls, dagrun: DagRun) -> str | None:
if hasattr(dagrun, "team_name"):
return dagrun.team_name
+ # Best-effort: the scheduler stamps `_team_name` on ORM DagRun objects
before
+ # listener hooks fire. It's a private attribute with no stability
guarantee,
+ # so guard with hasattr and an isinstance check.
+ if hasattr(dagrun, "_team_name"):
+ return dagrun._team_name if isinstance(dagrun._team_name, str)
else None
+
try:
- bundle_name = cls.dag_version_info(dagrun, "bundle_name")
- if not isinstance(bundle_name, str):
+ from sqlalchemy.orm import object_session
+
+ session = object_session(dagrun)
+
+ if session is None:
return None
- from airflow.models.dagbundle import DagBundleModel
+ from airflow.models.dag import DagModel
- return DagBundleModel.get_team_name(bundle_name)
+ return DagModel.get_team_name(dagrun.dag_id, session=session)
Review Comment:
I am curious about why youare using `get_team_name()` on `DagModel` rather
than `DagBundleModel`? Since the ownership relationship is Team -> DagBundle ->
DagModel, I'm wondering whether the bundle model is a more natural home for
this lookup.
##########
providers/openlineage/src/airflow/providers/openlineage/utils/utils.py:
##########
@@ -1073,18 +1080,27 @@ def team_name(cls, dagrun: DagRun) -> str | None:
if hasattr(dagrun, "team_name"):
return dagrun.team_name
+ # Best-effort: the scheduler stamps `_team_name` on ORM DagRun objects
before
+ # listener hooks fire. It's a private attribute with no stability
guarantee,
+ # so guard with hasattr and an isinstance check.
+ if hasattr(dagrun, "_team_name"):
+ return dagrun._team_name if isinstance(dagrun._team_name, str)
else None
+
try:
- bundle_name = cls.dag_version_info(dagrun, "bundle_name")
- if not isinstance(bundle_name, str):
+ from sqlalchemy.orm import object_session
+
+ session = object_session(dagrun)
Review Comment:
Doing this in fairly atypical in the provider so it's best to add a comment
like this to explain why:
```
# Reuse the existing ORM session associated with the DagRun. Creating a new
# session here (via @provide_session) can trigger an unexpected commit within
# the scheduler callback, which breaks HA lock semantics.
```
--
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]