-
Notifications
You must be signed in to change notification settings - Fork 14.5k
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
Add pre-upgrade check for dangling TI references #22924
Conversation
b1f8b90
to
d1296aa
Compare
tested on all 4 dbs Test data: testing from pre-2.2.0: test_2_1_4.txt procedure: delete and recreate db |
30ec003
to
2f66ae9
Compare
4533c18
to
2b73d51
Compare
OK @ashb @uranusjr i think this is ready for a look. Recall that prior to this PR, we had "missing dag run" checks for dangling rows. But this wasn't quite all that we needed. It made sense for TaskInstance, when we added run_id to it in 2.2.0. However, for the other tables we are changing in 2.3.0, checking for the existence of a DagRun is not actually strict enough, since we're keying to TI -- we need to look for a record in TI.join(DR). Initially I thought I should add a second set of checks -- for TI -- alongside the DR checks. But, since the check for dangling TI ref implies a check for dangling DR ref, we can skip the DR check and just check for TI. This enables us to do all checks (missing DR and missing TI) in the same loop, though this required a bit of a refactor. One complication is that when db < 2.2.0 the join conditions for TI.join(DR) are different from when 2.2.0 <= db < 2.3.0. Initially I was going to read airflow version of db for this determination, but it ended up being easy enough to use a "duck typing" inference approach. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems good to me
00463f8
to
7599f4d
Compare
We are adding some foreign keys in 2.3.0 so we want make it more likely that migration succeeds by detecting FK violations and moving the records out of the table before creating the FK. We already had a check for dag run but this adds one for TaskInstance.
7599f4d
to
5e9211d
Compare
The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest main at your convenience, or amend the last commit of the PR, and push it with --force-with-lease. |
We are adding some foreign keys in 2.3.0 so we want make it more likely that migration succeeds by detecting FK violations and moving the records out of the table before creating the FK. We already had a check for dag run but this adds one for TaskInstance.