Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import order for task_instance_mutation_hook #15851

Merged
merged 1 commit into from
May 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion airflow/models/dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from airflow.exceptions import AirflowException, TaskNotFound
from airflow.models.base import ID_LEN, Base
from airflow.models.taskinstance import TaskInstance as TI
Copy link

Choose a reason for hiding this comment

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

Suggested change
from airflow.models.taskinstance import TaskInstance as TI
from airflow.models.taskinstance import TaskInstance as TI
from airflow.settings import task_instance_mutation_hook

Copy link
Member

@ashb ashb May 14, 2021

Choose a reason for hiding this comment

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

The fix is to quite literally delay the import, to avoid an import cycle.

At the point this was imported, the local settings hadn't been applied, so this was always going to be a no-op.

from airflow.settings import task_instance_mutation_hook
ashb marked this conversation as resolved.
Show resolved Hide resolved
from airflow.stats import Stats
from airflow.ti_deps.dep_context import DepContext
from airflow.ti_deps.dependencies_states import SCHEDULEABLE_STATES
Expand Down Expand Up @@ -633,6 +632,8 @@ def verify_integrity(self, session: Session = None):
:param session: Sqlalchemy ORM Session
:type session: Session
"""
from airflow.settings import task_instance_mutation_hook

dag = self.get_dag()
tis = self.get_task_instances(session=session)

Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_dagrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ def test_already_added_task_instances_can_be_ignored(self):
assert State.NONE == first_ti.state

@parameterized.expand([(state,) for state in State.task_states])
@mock.patch('airflow.models.dagrun.task_instance_mutation_hook')
@mock.patch('airflow.settings.task_instance_mutation_hook')
def test_task_instance_mutation_hook(self, state, mock_hook):
def mutate_task_instance(task_instance):
if task_instance.queue == 'queue1':
Expand Down