-
Notifications
You must be signed in to change notification settings - Fork 64
Improved datetime comparison logic #170
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
Conversation
In general, you can rely on the fact that the datetimes are UTC, so I believe stripping timezone data is OK... but I am not positive about that. |
from ..models.history import HistoryEventType | ||
from ..constants import DATETIME_STRING_FORMAT | ||
from azure.functions._durable_functions import _deserialize_custom_object | ||
from datetime import datetime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is the new datetime format we are using. Is there anyway for us to remove the reference to the old datetime format so it isn't accidentally used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the same datetime format as before, I just needed to explicitly import it now, because I needed to use its datettime.strptime
parser.
I'll write some more thoughts on the "two datetime variants" in a comment below.
I want to correct my previous explanation of the problem we were seeing, as it's no longer correct. Problem Description So here's concretely the issue. Given a Note that the two timestamps are equivalent, but the latter drops redundant zeroes to the left. I think this is not happening at the Durable Python SDK, so I have to assume it's happening either at the I have also added a test to this PR to prevent regressions on this specific error. On the 2 datetime representations Finally, I also made this comment about having timezone-aware and timezone-naive datetime objects. I should not have made that comment now that I think about it because it explains nothing about the error. However, for completeness, the problem is that datetime objects created via One final To-Do The Python Durable tests also assert the correctness of the orchestration state schema and I'm getting errors when validating the correctness of the schema when timers are present. In particular, I'm seeing:
Where can I find an up-to-date schema definition with these two fields? 🦓 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Addresses: #168
This PR improves our
datetime
comparison logic, which is crucial for finding durable-timer-creation events in the state array. Before, we compareddatetime
objects using theirtoString
representation, but somedatetime
subtypes (timezone aware datetimes) have a slightly different string representations of dates. As a result, some equivalent dates failed to actually be acknowledged as equal.The solution here takes two steps. First, instead of comparing strings, we compare proper
datetime
objects against each other. However, timezone-awaredatetime
s and timezone-naivedatetime
s are not directly comparable. As a result, I force alldatetime
objects to be timezone-naive, but I'm unsure how safe this is, and worry about this breaking in the cloud.I'm not sure of why we have the two
datetime
variants floating in our codebase. It would be good to unify their representations. Are the dates flowing through durable-extension always in the same timezone? If so, I could force them all to be under that timezone, which strikes me as safer than removing the timezone metadata.Happy to explain this further, if needed!