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 model loading order of DagRunNote vs User #35614

Closed
wants to merge 1 commit into from

Conversation

Kache
Copy link
Contributor

@Kache Kache commented Nov 13, 2023

It seems DagRun gets loaded before User, resulting in a
sqlalchemy.exc.NoReferencedTableError (at least when running airflow tasks test DAG_ID TASK_ID) when defining DagRun's foreign key to the
still nonexistent User table.

Referencing the column object instead of using str establishes proper
import ordering and fixes the issue.

Fix: #34109

It seems DagRun gets loaded before User, resulting in a
sqlalchemy.exc.NoReferencedTableError (at least when running `airflow
tasks test DAG_ID TASK_ID`) when defining DagRun's foreign key to the
still nonexistent User table.

Referencing the column object instead of using str establishes proper
import ordering and fixes the issue.

Fix: apache#34109
@potiuk
Copy link
Member

potiuk commented Nov 13, 2023

I don't think this is a good approach. We are trying to move out FAB to separate provider (see #32210 and likely we do not want to keep reference to Fab user table in Note. That would be something to be solved - I think - in the way to break the relation altogether - this field in Note should accept any user id - not only one coming from FAB user table.

@potiuk
Copy link
Member

potiuk commented Nov 13, 2023

cc: @vincbeck

@vincbeck
Copy link
Contributor

I don't think this is a good approach. We are trying to move out FAB to separate provider (see #32210 and likely we do not want to keep reference to Fab user table in Note. That would be something to be solved - I think - in the way to break the relation altogether - this field in Note should accept any user id - not only one coming from FAB user table.

Good catch! And I +1 on this one :)

Copy link
Contributor

@vincbeck vincbeck left a comment

Choose a reason for hiding this comment

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

As mentioned, we dont want to reference the User table in core Airflow

@Kache
Copy link
Contributor Author

Kache commented Nov 14, 2023

Thanks for elaborating on the broader implications.

Isn't "trying to move out FAB to separate provider" a separate feature/refactor concern? It's simply currently the case that User is referenced in DagRunNote as "ab_user.id", and this change is just making the current state of things explicit enough for Python to load modules in dependency order.

This change shouldn't make moving out FAB more difficult either. Would you guys think it sufficient to add TODO comments in reference to #32210 or additional notes elsewhere?

Alternatively, perhaps the foreign key constraint could be removed entirely, but that seems to require a migration which requires a bit more ceremony that I'm not familiar with.

@vincbeck
Copy link
Contributor

This change shouldn't make moving out FAB more difficult either. Would you guys think it sufficient to add TODO comments in reference to #32210 or additional notes elsewhere?

I am not in favor of this one. This is postponing the problem and does not solve it. I am not too familiar either but removing the foreign key might be the solution for that. I'd wait for @potiuk to confirm though

@potiuk
Copy link
Member

potiuk commented Nov 14, 2023

Isn't "trying to move out FAB to separate provider" a separate feature/refactor concern? It's simply currently the case that User is referenced in DagRunNote as "ab_user.id", and this change is just making the current state of things explicit enough for Python to load modules in dependency order.

This change shouldn't make moving out FAB more difficult either. Would you guys think it sufficient to add TODO comments in reference to #32210 or additional notes elsewhere?

I believe it's the same issue and there is 0 chance this PR will be out in 2.7.4 (if we have one) - it will at most get out in 2.8.0 (tentatively a month from now) - by which time we definitely want to have FAB as separate provider, and even if we do not make it on time, we should at least break the links between core DB and FAB DB.

So I'd rather treat this one as "thing to rememeber to solve WHEN we move". Merging it now when we know it's going to be changed later makes little sense and adds no value.

@potiuk
Copy link
Member

potiuk commented Nov 14, 2023

I am not in favor of this one. This is postponing the problem and does not solve it. I am not too familiar either but removing the foreign key might be the solution for that. I'd wait for @potiuk to confirm though

Yeah - as explained above - we should (separate PR) - remove the Foreign Key (and add migration to do so) - even if we will get the Provider separation later. This will solve the problem as well, and will be step in the direction we are heading rather than orthogonal to it.

@Kache
Copy link
Contributor Author

Kache commented Nov 14, 2023

I see, thanks for explaining. The workaround ought to suffice in the meantime, anyways.

@Kache Kache closed this Nov 14, 2023
@Kache Kache deleted the kache/fix-dag_run_note-model-init branch November 14, 2023 20:03
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.

sqlalchemy error when running CLI command airflow tasks test
3 participants