-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
Update code style for airflow db
commands to SQLAlchemy 2.0 style
#31486
Conversation
Hmm, db init is failing with
But |
9619d4b
to
d5943f4
Compare
It should be fine now. I think I went overboard and used the metadata we use in creating DB models to reflect tables |
d5943f4
to
43d43cb
Compare
be4a85a
to
fdeaf05
Compare
fdeaf05
to
f7bef4f
Compare
else: | ||
for tbl in tables: | ||
try: | ||
table_name = tbl if isinstance(tbl, str) else tbl.__tablename__ | ||
metadata.reflect(only=[table_name], extend_existing=True, resolve_fks=False) | ||
metadata.reflect(bind=bind, only=[table_name], extend_existing=True, resolve_fks=False) |
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.
Is the bind=bind
part still needed? You already set metadata.bind
above.
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.
Yeah. It was surprising to me too. Here's the warning that it throws:
/opt/airflow/airflow/utils/db.py:1023 RemovedIn20Warning: The ``bind`` argument for schema methods that invoke SQL against an engine or connection will be required in SQLAlchemy 2.0. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
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.
Do we need the metadata.bind
line also then? Seems odd to need both.
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.
Have removed it. I remember having some issues around the metadata but let's see if the CI passes cause I can't reproduce locally
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.
Here's the error https://github.com/apache/airflow/actions/runs/5083011128/jobs/9133579355?pr=31486#step:5:10813, adding the bind back...
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.
What happened was that the metadata that was returned by the function was not bound to any database. The other binds are for the reflect methods. Despite the session being bound to metadata, they still want the bind to happen on its method
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.
Maybe instead we can add bind=bind
explicitly to the method calls instead? Not sure how feasible that is without actually digging into the call stack.
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.
Seeing this now...taking a look
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.
See 8a08c05, let me know what you think
else: | ||
for tbl in tables: | ||
try: | ||
table_name = tbl if isinstance(tbl, str) else tbl.__tablename__ | ||
metadata.reflect(only=[table_name], extend_existing=True, resolve_fks=False) | ||
metadata.reflect(bind=bind, only=[table_name], extend_existing=True, resolve_fks=False) |
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.
Do we need the metadata.bind
line also then? Seems odd to need both.
35991d5
to
c2423ca
Compare
Please don't merge yet, investigating MSSQL failure locally(it's canceled on CI) |
c2423ca
to
98643ee
Compare
Resolved: 98643ee |
This commit introduces changes to the code styles of `airflow db` commands to remove 'RemovedIn20Warning' and ensure compatibility with SQLAlchemy 2.0. To see these warnings, you need to set SQLALCHEMY_WARN_20=True when using the db commands
98643ee
to
edbbb7e
Compare
This commit introduces changes to the code styles of
airflow db
commands to remove 'RemovedIn20Warning' and ensure compatibility with SQLAlchemy 2.0.To see these warnings, you need to set SQLALCHEMY_WARN_20=True when using the db commands
Part of #28723