-
Notifications
You must be signed in to change notification settings - Fork 14.8k
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
[Airflow 2.2.2] execution_date Proxy object - str formatting error #19716
Comments
Thanks for opening your first issue here! Be sure to follow the issue template! |
This can be worked around by implementing a proxy specific for datetime: >>> from lazy_object_proxy import Proxy
>>> class DTProxy(Proxy):
... def __format__(self, spec):
... return self.__wrapped__.__format__(spec)
...
>>> from airflow.utils.timezone import utcnow
>>> p = DTProxy(utcnow)
>>> f"{p:%Y-%m-%d}"
'2021-11-19' |
@uranusjr I have discovered a similar issue with from datetime import datetime
...
datetime.fromisoformat(next_ds)
TypeError: fromisoformat: argument must be str |
That is unfixable, I’m afraid, since the But you shouldn’t need to do this in the first place? Those exact values are already available directly in the context as |
👍🏻 This was an edge case on our end and I have already updated usage to |
Yeah. Agree with @uranusjr - we could potentially monkey-patch datetime, but this is not really worthy of that. Almost by definition, there are probably other cases and total compatibility with any python code written out there is not achievable, it will be far easier to fix those cases by the users. |
Apache Airflow version
2.2.2 (latest released)
Operating System
Ubuntu 18.04.6
Versions of Apache Airflow Providers
No response
Deployment
Other Docker-based deployment
Deployment details
No response
What happened
The deprecated variable
execution_date
raises an error when used in an f string template with date string formatting.What you expected to happen
Executing
f"{execution_date:%Y-%m-%d}"
should return a string and not raise an error.How to reproduce
Anything else
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: