-
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
AttributeError: 'datetime.timezone' object has no attribute 'name' #16551
Comments
I think the timezone argument was really designed to only except |
I honestly think we should completely get rid of Pendulum. I think it comes from the history where Airflow was also Python 2.7 compliant and Pendulum had many advantages over the standard datetime and friends. Right now with Python 3.6+ I see no reason why we should use Pendulum especially that it seems to be MUCH slower (like all the other non-native date parsing/handling libraries https://aboutsimon.com/blog/2016/08/04/datetime-vs-Arrow-vs-Pendulum-vs-Delorean-vs-udatetime.html). This is from 2016 so things might have changed since (and penduilum does have c extensions it seems), but I saw so many problems coming from us using it and mixing pendulum with native datetime. I remember a problem I spend hours looking for where different behaviour of Pendulum when passed datatime object in the presence or lack of fold parameter (one of the problems which only manifested in Python 3.5). |
I can't guarantee it but I think this is a regression, I mean I had (always) used But anyway I agree that you that probably you can quickly solve this particular issue and prevent lots of confused users by If checked and converting to pendulum datetime provides a
|
Not sure when do you mean by “before”, but the
That’s probably a good idea long term, but we’ll need some planning on this to re-write timezone functionalities in scheduling, which are heavily built around Pendulum right now. IMO unifying everything to Peendulum can likely help with the transition off Pendulum as well, if we only use the standard stuff (e.g. no |
This will be kinda painful I think since some of the most important macros are Pendulum and it's very common to do manipulation over it so this may require significant code changes per dag when upgrading version |
If you assign this to me I can do a PR that converts the input |
I can’t assign but feel free to go ahead. |
assigned :) |
Before I go any further: The current error comes from If we just convert the So there are some alternatives:
|
So it seems that currently the requirements for the
So I don't know, I can sure make it work for What I can do it's to do a fail-fast approach in |
Where exactly is this raised? >>> import datetime, pendulum
>>> pendulum.instance(datetime.datetime.now().replace(tzinfo=datetime.timezone.utc))
DateTime(2021, 6, 23, 5, 54, 45, 240168, tzinfo=Timezone('+00:00'))
>>> pendulum.instance(datetime.datetime.now().replace(tzinfo=datetime.timezone(datetime.timedelta(seconds=0))))
DateTime(2021, 6, 23, 5, 55, 45, 900498, tzinfo=Timezone('+00:00')) I’m using pendulum 2.1.2 (as specified in the official constraints). |
It will be raised later at So the following will raise InvalidTimezone:
because the pendulum's instance timezone will be Timezone("+00:00") with So in essence But anyway I just removed the usage of |
If we coerce the datetime object in (IOW you did the right thing removing it in the PR) |
Yes, and you will get rid of InvalidTimezone at Just to clarify my point, in the current (pre-PR) codebase if you provide a pendulum datetime with a non-named pendulum.timezone that will raise InvalidTimezone in
The PR #16599 will get rid of the |
… ``name`` (#16599) closes: #16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone.
… ``name`` (apache#16599) closes: apache#16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone.
… ``name`` (#16599) closes: #16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone. (cherry picked from commit 86c2091)
… ``name`` (#16599) closes: #16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone. (cherry picked from commit 86c2091)
… ``name`` (#16599) closes: #16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone. (cherry picked from commit 86c2091)
… ``name`` (#16599) closes: #16551 Previous implementation tried to force / coerce the provided timezone (from the dag's `start_date`) into a `pendulum.tz.timezone.*` that only worked if the provided timezone was already a pendulum's timezone and it specifically failed when with `datetime.timezone.utc` as timezone. (cherry picked from commit 86c2091)
Apache Airflow version: 2.0.2
Kubernetes version (if you are using kubernetes) (use
kubectl version
):Environment:
uname -a
):What happened:
In a DAG with
datetime(2021, 5, 31, tzinfo=timezone.utc)
it will raise anAttributeError: 'datetime.timezone' object has no attribute 'name'
in the scheduler.It seems that airflow relies on the tzinfo object to have a
.name
attribute so the "canonical"datetime.timezone.utc
does not comply with that requirement.What you expected to happen:
If
start_date
or any other input parameter requires atzinfo
with aname
attribute it should check for that in the DAG object and produce a more specific error message notAttributeError
.Also I guess this requirement should be explicitly mentioned in https://airflow.apache.org/docs/apache-airflow/stable/timezone.html with a comment like
Or even better it would be not to rely on the presence of a
name
attribute in the tzinfo....How to reproduce it:
Anything else we need to know:
The text was updated successfully, but these errors were encountered: