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

Move the DagRun-TaskInstance relationship to TaskInstance #17016

Closed
wants to merge 1 commit into from

Conversation

uranusjr
Copy link
Member

@ashb I think this is what’s needed?

Fix #16896, close #16960.

DagRun.task_instances is not actually used in Airflow anywhere, so the static check hack is not needed for the new relationship’s backref. But the backref itself is kept for compatibility.

String reference is used instead to avoid circular imports.

Not sure how this should be tested.

@penggongkui
Copy link
Contributor

according the sqla document, backref in dag_run or task_instance has same resullt, maybe change it to back_populates.

and delete dag_run need also delete related task_instance, maybe the relationship is needed by dag_run

A relationship implies cascading behavior when a row is deleted in
SQLAlchemy. Defining the relationship on DagRun means the TaskInstance
becomes a "parent" to DagRun, thus deleting a TaskInstance automatically
clears its associating DagRun's foreign key fields, which is not what we
want. The relationship should be the other way around -- deleting a
DagRun should clear its associating TaskInstance row's foreign key
fields, so we move the relationship to the other side.
@uranusjr uranusjr force-pushed the taskinstance-child-dagrun branch from fdd52be to a2b4a51 Compare July 15, 2021 23:52

TaskInstance.dag_run = relationship(DagRun)
Copy link
Member

Choose a reason for hiding this comment

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

The primary reason for having this was to help with code-completion, so maybe we should keep the relationship on dagrun and change backref to back_populates as suggested

@penggongkui
Copy link
Contributor

Any update on this? I have to change the code by myself to avoid the delete dag issue after migrate airflow. Is it possible fixed it in 2.1.3?

@uranusjr
Copy link
Member Author

I’m not actively working on this right now. Feel free to submit a superceding PR.

@ashb
Copy link
Member

ashb commented Sep 3, 2021

Closing in favour of #17719

@ashb ashb closed this Sep 3, 2021
@uranusjr uranusjr deleted the taskinstance-child-dagrun branch September 3, 2021 12:13
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.

Deleting task instance from UI deletes Dag Run too
3 participants