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

DeepDiff Fails to Detect Timezone Changes in Arrays with ignore_order=True #517

Conversation

3schwartz
Copy link

@3schwartz 3schwartz commented Jan 9, 2025

Solution proposal for issue #516

Description

The deepdiff library is unable to detect timezone changes in datetimes within arrays.

When ignore_order=True and a datetime is present within an array, deepdiff uses an execution path that makes a DeepHash. Due to the implementation of datetime_normalize, all datetimes have their timezone set to UTC:

obj = obj.replace(tzinfo=datetime.timezone.utc)

This behavior causes issues in our use case, as we rely on deepdiff to detect changes in datetime objects, including changes to their timezones.

Changes

Indent logic which replaces timezone to only affect those which has set truncate_datetime.

Notes

Existing logic was added in commits

@seperman
Copy link
Owner

seperman commented Feb 3, 2025

Hi @3schwartz
Thanks for making the PR! Looking at it now.

Copy link
Owner

@seperman seperman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @3schwartz
We currently treat timezone naive datetime objects as UTC datetimes. That is independent from truncate_datetime.
This also made me realize that we should convert the datetimes that have explicit timezone to their respective datetimes in UTC instead of "replacing" the timezone.
I have copy pasted your test and am playing with that idea. I will keep you posted.

@seperman
Copy link
Owner

seperman commented Feb 4, 2025

@3schwartz Your PR made me realize we need to be more consistent with our timezone logic. I changed our logic to:

  • Convert any datetime with timezone to the respective time in UTC
  • Assume any timezone naive datetime to be in UTC

That has a conflict with what you wanted in your tests.
You can see the outcome of what I did here:
000ec0b

@seperman seperman closed this Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants