Fix RecursionError when adding to a DateTime with a FixedTimezone#431
Merged
sdispater merged 1 commit intopython-pendulum:masterfrom Jan 25, 2020
pR0Ps:master
Merged
Fix RecursionError when adding to a DateTime with a FixedTimezone#431sdispater merged 1 commit intopython-pendulum:masterfrom pR0Ps:master
sdispater merged 1 commit intopython-pendulum:masterfrom
pR0Ps:master
Conversation
This seems to have been caused by `bpo-32417`. Before that change, adding a timedelta to a date/datetime subclass would always return an instance of date/datetime instead of the subclass. After the change, the subclass is preserved. The RecursionError was caused by adding a timedelta to a DateTime. Doing this uses the `convert` method of the DateTime's timezone to convert the new DateTime into the correct timezone. In the case of FixedTimezones, this requires adding the UTC offset of the timezone (a timedelta) to the DateTime, causing the recursion. Before bpo-32417, the subclass of the DateTime was dropped while calling `astimezone`. This meant that the object that was passed into `fromutc` by `astimezone` was a stdlib datetime, not a Pendulum DateTime. Calling the stdlib datetime's add function would then do the addition and return the result (which would then be upconverted back into a Pendulum DateTime instance). Now, due to the subclass being preserved, the Pendulum DateTime's add function is being called instead, causing the recursion. This commit fixes the RecursionError by always using the stdlib datetime's addition function to add the offset to the DateTime when calling fromutc. bpo-32417: https://bugs.python.org/issue32417 commit: python/cpython@89427cd Fixes #422
Collaborator
|
Thanks a lot for your contribution! |
|
Will there be a new release that includes this PR anytime soon? |
Merged
ghost
pushed a commit
to team-machine/tap-pipedrive
that referenced
this pull request
Aug 7, 2020
DavidWittman
added a commit
to DavidWittman/serverless-southwest-check-in
that referenced
this pull request
Dec 12, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This seems to have been caused by
bpo-32417. Before that change, adding a timedelta to a date/datetime subclass would always return an instance of date/datetime instead of the subclass. After the change, the subclass is preserved.The RecursionError was caused by adding a timedelta to a DateTime. Doing this uses the
convertmethod of the DateTime's timezone to convert the new DateTime into the correct timezone. In the case of FixedTimezones, this requires adding the UTC offset of the timezone (a timedelta) to the DateTime, causing the recursion.Before bpo-32417, the subclass of the DateTime was dropped while calling
astimezone. This meant that the object that was passed intofromutcbyastimezonewas a stdlib datetime, not a Pendulum DateTime. Calling the stdlib datetime's add function would then do the addition and return the result (which would then be upconverted back into a Pendulum DateTime instance). Now, due to the subclass being preserved, the Pendulum DateTime's add function is being called instead, causing the recursion.This commit fixes the RecursionError by always using the stdlib datetime's addition function to add the offset to the DateTime when calling
fromutc.bpo-32417: https://bugs.python.org/issue32417
commit: python/cpython@89427cd
Fixes #422