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

Replace datetime.datetime.utcnow by airflow.utils.timezone.utcnow in core #35448

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

Taragolis
Copy link
Contributor

@Taragolis Taragolis commented Nov 4, 2023

This one deprecated in Python 3.12, see What’s New In Python 3.12: Deprecated

datetime: datetime.datetime’s utcnow() and utcfromtimestamp() are deprecated and will be removed in a future version. Instead, use timezone-aware objects to represent datetimes in UTC: respectively, call now() and fromtimestamp() with the tz parameter set to datetime.UTC. (Contributed by Paul Ganssle in gh-103857.)

We still far away of support Python 3.12

Related: #32344


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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.

@boring-cyborg boring-cyborg bot added area:logging area:Scheduler including HA (high availability) scheduler area:webserver Webserver related Issues labels Nov 4, 2023
@Taragolis Taragolis force-pushed the replace-deprecated-utcnow-core branch from ecdaccf to 27d6904 Compare November 4, 2023 22:51
airflow/utils/timezone.py Outdated Show resolved Hide resolved
Copy link

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Dec 22, 2023
@Taragolis Taragolis removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Dec 23, 2023
@Taragolis Taragolis force-pushed the replace-deprecated-utcnow-core branch from 27d6904 to 7571025 Compare January 13, 2024 15:47
@Taragolis Taragolis force-pushed the replace-deprecated-utcnow-core branch from 7571025 to d910f84 Compare January 31, 2024 01:55
@Taragolis Taragolis added the full tests needed We need to run full set of tests for this PR to merge label Jan 31, 2024
@Taragolis
Copy link
Contributor Author

Finally I have a time to resolve all usage of datetime.datetime.utcnow (deprecated in Python 3.12) and pendulum.DateTime.utcnow (just tried to reduce direct usage of pendulum) into the core and resolve all failing tests.

@potiuk
Copy link
Member

potiuk commented Jan 31, 2024

Nice. Those were also causing max recursion errors in the Python 3.12 PR

@Taragolis
Copy link
Contributor Author

I guess this changes also could make some internal components more consistent, because datetime.datetime.utcnow return naive object and at least into the some tests it makes it failure if local timezone non UTC

@Taragolis
Copy link
Contributor Author

There is still remaining usage into the dev and providers tests, which I've plan to fix as follow up.
And after that we could ban datetime.datetime.utcnow import and usage on entire project by add into the tool.ruff.flake8-tidy-imports.banned-api rule

[tool.ruff.flake8-tidy-imports.banned-api]                                                                         
...      
"datetime.datetime.utcnow".msg = "Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)"
pre-commit run ruff --all-files
Run 'ruff' for extremely fast Python linting.............................Failed
- hook id: ruff
- exit code: 1

airflow/providers/google/cloud/transfers/s3_to_gcs.py:279:15: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
airflow/providers/google/common/hooks/base_google.py:673:41: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
dev/breeze/src/airflow_breeze/utils/parallel.py:286:27: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
dev/breeze/src/airflow_breeze/utils/parallel.py:315:23: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
kubernetes_tests/test_base.py:80:32: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
scripts/in_container/update_quarantined_test_status.py:239:26: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
Found 6 errors.
tests/providers/celery/executors/test_celery_executor.py:186:22: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/cncf/kubernetes/executors/test_kubernetes_executor.py:453:37: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/cncf/kubernetes/executors/test_kubernetes_executor.py:1420:48: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/cncf/kubernetes/executors/test_kubernetes_executor.py:1450:48: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/cncf/kubernetes/executors/test_kubernetes_executor.py:1484:48: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/google/cloud/sensors/test_gcs.py:75:37: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/providers/google/cloud/triggers/test_gcs.py:44:18: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/system/providers/google/cloud/storage_transfer/example_cloud_storage_transfer_service_aws.py:90:29: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
tests/system/providers/google/cloud/storage_transfer/example_cloud_storage_transfer_service_gcp.py:86:29: TID251 `datetime.datetime.utcnow` is banned: Use airflow.utils.timezone.utcnow or datetime.datetime.utc(tz=...)
Found 9 errors.

@potiuk potiuk merged commit 2f07c6b into apache:main Jan 31, 2024
81 checks passed
@Taragolis Taragolis deleted the replace-deprecated-utcnow-core branch February 1, 2024 19:50
@ephraimbuddy ephraimbuddy added the type:misc/internal Changelog: Misc changes that should appear in change log label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:logging area:Scheduler including HA (high availability) scheduler area:webserver Webserver related Issues full tests needed We need to run full set of tests for this PR to merge type:misc/internal Changelog: Misc changes that should appear in change log
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants