You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dondaum (via GitHub)" <gi...@apache.org> on 2024/04/23 23:02:42 UTC
[PR] fix: sqa deprecations for airflow core [airflow]
dondaum opened a new pull request, #39211:
URL: https://github.com/apache/airflow/pull/39211
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
related: #28723
fix deprecations for SQLAlchemy 2.0 for Airflow core.
@Taragolis I linked your changes as well in the list.
Further I have noticed 2 things. First of all I fixed an issue that was not listed in the orginal issue. I assume it might was missing as it a mysql specfic, e.g. [example](https://github.com/apache/airflow/blob/main/airflow/utils/db_cleanup.py#L166) Thus it would make sense to run the checks for mysql and any other supported db as well.
Second I could not fix `airflow/cli/commands/task_command.py:202` and I am not really sure if this is really something that needs to be fixed. I went through the SQA docs and it might be a warning we have in 1.4 that will be gone whenever we have 2.0 without any real error. But hard to tell. I will further investigate.
### Reported in core
- [x] airflow/models/taskinstance.py:1869 fixed by #39195
- [x] airflow/models/taskinstance.py:1871 fixed by #39195
- [x] airflow/www/views.py:845
- [x] airflow/www/views.py:3455
- [x] airflow/www/views.py:3455
- [x] airflow/www/views.py:3293
- [x] airflow/www/views.py:3293
- [x] airflow/jobs/scheduler_job_runner.py:1642 fixed by #39195
- [x] airflow/utils/db_cleanup.py:200
- [ ] airflow/cli/commands/task_command.py:202
- [x] airflow/models/taskinstance.py:524 fixed by #39195
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1578979638
##########
airflow/www/views.py:
##########
@@ -3294,7 +3292,7 @@ def next_run_datasets(self, dag_id):
latest_run = dag_model.get_last_dagrun(session=session)
events = [
- dict(info)
+ dict(info._mapping)
Review Comment:
Yeah... That rare case when access to properties with leading underscore is official/recommended way:
- https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.Row._mapping
- https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Row._mapping
This one is come from the warning it self
```console
The Row.keys() method is considered legacy as of the 1.x series of SQLAlchemy and will be removed in 2.0.
Use the namedtuple standard accessor Row._fields, or for full mapping behavior use row._mapping.keys()
(Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "dondaum (via GitHub)" <gi...@apache.org>.
dondaum commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1577922242
##########
airflow/utils/db_cleanup.py:
##########
@@ -167,7 +168,7 @@ def _do_delete(*, query, orm_model, skip_archive, session):
# MySQL with replication needs this split into two queries, so just do it for all MySQL
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
session.execute(text(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}"))
- metadata = reflect_tables([target_table_name], session)
+ metadata.reflect(bind, only=[target_table_name])
Review Comment:
> Seems like it doesn't fix `airflow/utils/db_cleanup.py:201`
>
> ```
> =============================== Group 'airflow' ================================
> Saved into file: /home/runner/work/airflow/airflow/files/warn-summary-group-airflow.txt
>
> Unique warnings within the test cases: 193
>
> Top 10 Tests Cases:
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_no_encryption - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_with_encryption - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_with_encryption_rotate_fernet_key - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_from_uri - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_get_uri_from_conn - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_get_uri_from_uri - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_from_json_extra - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/api_connexion/endpoints/test_connection_endpoint.py::TestGetConnection::test_should_respond_200 - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/api_connexion/schemas/test_connection_schema.py::TestConnectionSchema::test_serialize - 3 (!)
> airflow.exceptions.RemovedInAirflow3Warning tests/providers/yandex/secrets/test_lockbox.py::TestLockboxSecretBackend::test_yandex_lockbox_secret_backend_get_connection_from_json - 3 (!)
>
> Unique warnings: 53
>
> Warnings grouped by category:
> airflow.exceptions.RemovedInAirflow3Warning - 28 (!)
> DeprecationWarning - 13
> airflow.exceptions.AirflowProviderDeprecationWarning - 5 (!)
> UserWarning - 2
> sqlalchemy.exc.RemovedIn20Warning - 2 (!!!)
> sqlalchemy.exc.SAWarning - 2 (!!)
> FutureWarning - 1
>
> Top 10 Warnings:
> airflow/models/connection.py:177:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
> airflow/models/connection.py:370:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
> airflow/models/connection.py:376:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
> airflow/www/views.py:1745:airflow.exceptions.RemovedInAirflow3Warning - 2 (!)
> airflow/utils/db.py:1069:sqlalchemy.exc.SAWarning - 2 (!!)
> airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:48:DeprecationWarning - 1
> airflow/cli/commands/info_command.py:232:DeprecationWarning - 1
> airflow/settings.py:196:DeprecationWarning - 1
> airflow/utils/session.py:81:DeprecationWarning - 1
> airflow/utils/session.py:84:DeprecationWarning - 1
>
> -------------------------- Always reported warnings 4---------------------------
> airflow/utils/db.py:1069
> sqlalchemy.exc.SAWarning - Skipped unsupported reflection of expression-based index idx_ab_user_username
>
> airflow/utils/db.py:1069
> sqlalchemy.exc.SAWarning - Skipped unsupported reflection of expression-based index idx_ab_register_user_username
>
> airflow/utils/db_cleanup.py:201
> sqlalchemy.exc.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)
>
> airflow/cli/commands/task_command.py:202
> sqlalchemy.exc.RemovedIn20Warning - "TaskInstance" object is being merged into a Session along the backref cascade path for relationship "DagRun.task_instances"; in SQLAlchemy 2.0, this reverse cascade will not take place. Set cascade_backrefs to False in either the relationship() or backref() function for the 2.0 behavior; or to set globally for the whole Session, set the future=True flag (Background on this error at: https://sqlalche.me/e/14/s9r1) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
> ```
>
> See: https://github.com/apache/airflow/actions/runs/8813920521/job/24196107977?pr=39211 And just in case warning summary artifact: [test-summarized-warnings (4).zip](https://github.com/apache/airflow/files/15093686/test-summarized-warnings.4.zip)
Yes you are right. Thanks for checking.
I made a couple of wrong assumption that a) lead to a wrong implementation b) tricked me somehow while checking my local warnings.text.
Changed. I checked multiple times. There should be no more `RemovedIn20Warning` in `airflow/utils/db_cleanup.py:201`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1578826032
##########
airflow/www/views.py:
##########
@@ -3294,7 +3292,7 @@ def next_run_datasets(self, dag_id):
latest_run = dag_model.get_last_dagrun(session=session)
events = [
- dict(info)
+ dict(info._mapping)
Review Comment:
I assume this attribute is officially supported although it looks private
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1577606267
##########
airflow/utils/db_cleanup.py:
##########
@@ -167,7 +168,7 @@ def _do_delete(*, query, orm_model, skip_archive, session):
# MySQL with replication needs this split into two queries, so just do it for all MySQL
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
session.execute(text(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}"))
- metadata = reflect_tables([target_table_name], session)
+ metadata.reflect(bind, only=[target_table_name])
Review Comment:
BTW, locally it cover this case in MySQL backend in `tests/utils/test_db_cleanup.py::TestDBCleanup::test__cleanup_table`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "dondaum (via GitHub)" <gi...@apache.org>.
dondaum commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1577911561
##########
airflow/utils/db_cleanup.py:
##########
@@ -167,7 +168,7 @@ def _do_delete(*, query, orm_model, skip_archive, session):
# MySQL with replication needs this split into two queries, so just do it for all MySQL
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
session.execute(text(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}"))
- metadata = reflect_tables([target_table_name], session)
+ metadata.reflect(bind, only=[target_table_name])
Review Comment:
> BTW, locally it cover this case in MySQL backend in `tests/utils/test_db_cleanup.py::TestDBCleanup::test__cleanup_table`
Yes locally when using breeze with backend mysql it is working as expected and I get the warning as well.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr merged PR #39211:
URL: https://github.com/apache/airflow/pull/39211
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #39211:
URL: https://github.com/apache/airflow/pull/39211#discussion_r1577759015
##########
airflow/utils/db_cleanup.py:
##########
@@ -167,7 +168,7 @@ def _do_delete(*, query, orm_model, skip_archive, session):
# MySQL with replication needs this split into two queries, so just do it for all MySQL
# ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
session.execute(text(f"CREATE TABLE {target_table_name} LIKE {orm_model.name}"))
- metadata = reflect_tables([target_table_name], session)
+ metadata.reflect(bind, only=[target_table_name])
Review Comment:
Seems like it doesn't fix `airflow/utils/db_cleanup.py:201`
```console
=============================== Group 'airflow' ================================
Saved into file: /home/runner/work/airflow/airflow/files/warn-summary-group-airflow.txt
Unique warnings within the test cases: 193
Top 10 Tests Cases:
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_no_encryption - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_with_encryption - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_extra_with_encryption_rotate_fernet_key - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_from_uri - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_get_uri_from_conn - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_connection_get_uri_from_uri - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/always/test_connection.py::TestConnection::test_from_json_extra - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/api_connexion/endpoints/test_connection_endpoint.py::TestGetConnection::test_should_respond_200 - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/api_connexion/schemas/test_connection_schema.py::TestConnectionSchema::test_serialize - 3 (!)
airflow.exceptions.RemovedInAirflow3Warning tests/providers/yandex/secrets/test_lockbox.py::TestLockboxSecretBackend::test_yandex_lockbox_secret_backend_get_connection_from_json - 3 (!)
Unique warnings: 53
Warnings grouped by category:
airflow.exceptions.RemovedInAirflow3Warning - 28 (!)
DeprecationWarning - 13
airflow.exceptions.AirflowProviderDeprecationWarning - 5 (!)
UserWarning - 2
sqlalchemy.exc.RemovedIn20Warning - 2 (!!!)
sqlalchemy.exc.SAWarning - 2 (!!)
FutureWarning - 1
Top 10 Warnings:
airflow/models/connection.py:177:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
airflow/models/connection.py:370:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
airflow/models/connection.py:376:airflow.exceptions.RemovedInAirflow3Warning - 5 (!)
airflow/www/views.py:1745:airflow.exceptions.RemovedInAirflow3Warning - 2 (!)
airflow/utils/db.py:1069:sqlalchemy.exc.SAWarning - 2 (!!)
airflow/api_connexion/endpoints/forward_to_fab_endpoint.py:48:DeprecationWarning - 1
airflow/cli/commands/info_command.py:232:DeprecationWarning - 1
airflow/settings.py:196:DeprecationWarning - 1
airflow/utils/session.py:81:DeprecationWarning - 1
airflow/utils/session.py:84:DeprecationWarning - 1
-------------------------- Always reported warnings 4---------------------------
airflow/utils/db.py:1069
sqlalchemy.exc.SAWarning - Skipped unsupported reflection of expression-based index idx_ab_user_username
airflow/utils/db.py:1069
sqlalchemy.exc.SAWarning - Skipped unsupported reflection of expression-based index idx_ab_register_user_username
airflow/utils/db_cleanup.py:201
sqlalchemy.exc.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)
airflow/cli/commands/task_command.py:202
sqlalchemy.exc.RemovedIn20Warning - "TaskInstance" object is being merged into a Session along the backref cascade path for relationship "DagRun.task_instances"; in SQLAlchemy 2.0, this reverse cascade will not take place. Set cascade_backrefs to False in either the relationship() or backref() function for the 2.0 behavior; or to set globally for the whole Session, set the future=True flag (Background on this error at: https://sqlalche.me/e/14/s9r1) (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
```
See: https://github.com/apache/airflow/actions/runs/8813920521/job/24196107977?pr=39211
And just in case warning summary artifact: [test-summarized-warnings (4).zip](https://github.com/apache/airflow/files/15093686/test-summarized-warnings.4.zip)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #39211:
URL: https://github.com/apache/airflow/pull/39211#issuecomment-2074449930
> First of all I fixed an issue that was not listed in the orginal issue. I assume it might was missing as it a mysql specfic, e.g. [example](https://github.com/apache/airflow/blob/main/airflow/utils/db_cleanup.py#L166) Thus it would make sense to run the checks for mysql and any other supported db as well.
In theory it should be run against mysql backend, however difficult to say right now, seems like codecov integration broken again and there is difficult to say is this lines covered or not
> Second I could not fix airflow/cli/commands/task_command.py:202 and I am not really sure if this is really something that needs to be fixed. I went through the SQA docs and it might be a warning we have in 1.4 that will be gone whenever we have 2.0 without any real error. But hard to tell. I will further investigate.
This might not work as it expected into the 2.0 but better to check, it could be done by the separate PR. That what I found about particular this warning: https://github.com/sqlalchemy/sqlalchemy/discussions/7693#discussioncomment-2154599
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #39211:
URL: https://github.com/apache/airflow/pull/39211#issuecomment-2074451495
Set to rerun it with full test just in case
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix: sqa deprecations for airflow core [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis closed pull request #39211: fix: sqa deprecations for airflow core
URL: https://github.com/apache/airflow/pull/39211
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org