Skip to content

Mock out span generation for dag.test#48982

Merged
ashb merged 1 commit intoapache:mainfrom
aws-mwaa:onikolas/dag_test_span
Apr 9, 2025
Merged

Mock out span generation for dag.test#48982
ashb merged 1 commit intoapache:mainfrom
aws-mwaa:onikolas/dag_test_span

Conversation

@o-nikolas
Copy link
Copy Markdown
Contributor

Create an active span for the dag run before we call update_state on it for the first time. This way the span generation code does not run (which fails to work in the context see traceback below), we don't care about spans in the context of dag.test anyway.

Here is the exception that was thrown before this PR as a result of #43941:

devel-common/src/tests_common/test_utils/system_tests.py:68: in test_run
    dag_run = dag.test(
airflow-core/src/airflow/utils/session.py:102: in wrapper
    return func(*args, session=session, **kwargs)
airflow-core/src/airflow/models/dag.py:1705: in test
    schedulable_tis, _ = dr.update_state(session=session)
airflow-core/src/airflow/utils/session.py:99: in wrapper
    return func(*args, **kwargs)
airflow-core/src/airflow/models/dagrun.py:1197: in update_state
    self.start_dr_spans_if_needed(tis=tis)
airflow-core/src/airflow/utils/session.py:102: in wrapper
    return func(*args, session=session, **kwargs)
airflow-core/src/airflow/models/dagrun.py:968: in start_dr_spans_if_needed
    if self.span_status == SpanStatus.NOT_STARTED or self.span_status == SpanStatus.NEEDS_CONTINUANCE:
/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py:487: in __get__
    return self.impl.get(state, dict_)
/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py:959: in get
    value = self._fire_loader_callables(state, key, passive)
/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/attributes.py:990: in _fire_loader_callables
    return state._load_expired(state, passive)
/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/state.py:712: in _load_expired
    self.manager.expired_attribute_loader(self, toload, passive)
/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/loading.py:1369: in load_scalar_attributes
    raise orm_exc.DetachedInstanceError(
E   sqlalchemy.orm.exc.DetachedInstanceError: Instance <DagRun at 0x75a69394bbe0> is not bound to a Session; attribute refresh operation cannot proceed (Background on this error at: https://sqlalche.me/e/14/bhk3)

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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.

@o-nikolas o-nikolas requested review from XD-DENG and ashb as code owners April 8, 2025 22:57
Copy link
Copy Markdown
Contributor

@ferruzzi ferruzzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like a reasonable workaround

@ashb ashb merged commit 4216fda into apache:main Apr 9, 2025
50 checks passed
@vincbeck vincbeck deleted the onikolas/dag_test_span branch April 9, 2025 13:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants