-
Notifications
You must be signed in to change notification settings - Fork 67
[AL-5784] Remove backports because it failed to installed on Windows #1119
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
4b645af
to
529668c
Compare
529668c
to
4a8c474
Compare
Hi @vbrodsky , dateutil looks like a promising choice for sure! But looks like https://docs.python.org/3/library/datetime.html is being used for date conversions consistently throughout the repository. It probably fits your usecase too. Suggesting just to reduce one extra dependency. Sorry. |
labelbox/utils.py
Outdated
return dt.strftime(ISO_DATETIME_FORMAT) |
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.
Does this work if we're not backporting anymore? I see format_iso_datetime
is still being 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.
A very good point and I am glad you have asked
This function uses strftime
and I have tested it and found working the same with and without backport, so I have decided to keep it in light of the immediate goal of this story
HOWEVER I have raised it in this PR this function does not convert timezones into UTC correctly... I was hesitant to address it as a part of this story since no one has ever flagged this as an issue before
LMK, happy to address it here or as a separate ticket
tests/unit/test_utils.py
Outdated
('2011-11-04T00:05:23Z', '2011-11-04T00:05:23Z'), | ||
('2011-11-04T00:05:23+00:00', '2011-11-04T00:05:23Z'), | ||
('2011-11-04T00:05:23+05:00', '2011-11-04T00:05:23Z' | ||
), #NOTE not converting with timezone... this is compatible with out current implementation |
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.
Seeing some typos around the comments. Since it's a public repository, let's make sure we don't have too many of these :)
Could you proofread all the comments?
@yamini-labelbox are you saying that the dateutil library under the hood uses python datetime?
hi @yamini-labelbox (dunno why I can't just use a github Reply... in our thread) but here it is. The reason I am not using Python datetime library is exactly because the I am going to update the PR description to outline not just WHAT I did, but WHY I did it |
4a8c474
to
b2f348d
Compare
Make comments read better
Testing - prebackport
Here are the results: |
Testing with backport. Here is the script
src/labelbox-python - (v.3.46.0^2~31) > python ./test_date_with_backports.py |
Post backport:
parsing 2011-11-04T00:05:23Z |
@@ -838,7 +838,7 @@ def _validate_parse_number( | |||
def _validate_parse_datetime( | |||
field: DataRowMetadataField) -> List[Dict[str, Union[SchemaId, str]]]: | |||
if isinstance(field.value, str): | |||
field.value = datetime.fromisoformat(field.value) | |||
field.value = format_iso_from_string(field.value) |
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.
From line 849, we take the field.value
and convert it into string from the datetime using format_iso_datetime
. Since format_iso_datetime
does not take into consideration the timezone, does that mean that the timezone information will get lost here?
For instance, if user inputs 2011-11-04T00:05:23+05:00
as the date metadata, it looks like we'll be upserting 2011-11-04T00:05:23
and the timezone value gets lost? Let me know if I'm not understanding this correctly
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.
Time zone does get lost! This is existing before... that was my question - should I fix it?
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.
Yes, I know the original issue was to make sure the time string gets properly parsed if timezone passed in.. we should make this also properly parse the timezone, because otherwise, non-UTC timezones will not store accurate datetimes
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.
ok... to be clear format_iso_from_string
is not a problem, as far as I remember from my testing format_iso_datetime
is the problem, it just formats a string with a Z
time zone, no conversion. Those two functions are used together in the code (like to validate string is a valid datetime AND convert it back to string)
Thank you, Val!!!! 👍 |
BACKGROUND
Prior to 3.11, Python
datetime.fromisoformat()
function did not deal well with some accepted iso string formats we would like to support for the sdk. Python has addressed this in newer versions, beginning with 3.11In sdk v3.44.0 we have install a backport to use the 3.11 version of
fromisoformat()
. Unfortunately, our users had problems installing the backport on Windows. Consequently, they are blocked from upgrading our sdk.Just removing the backport is not enough, it would revert to older version
datetime.fromisoformat()
and would break time string parsing again. So we have switched to using the dateutils datetime string parsing and it works.I have created 3 scripts each matching to pre-, during- and post-backport (current). The results and the scripts will be attached.
backports.datetime_fromisoformat
that did not install well on Windows. The new library is Apache2 licensed (compliant with our open source licensing policy) and passed on Snyk, so all good for us to useformat_iso_from_string
will preserve timezones, however it's sister functionformat_iso_datetime
just takes current value of datetime and formats it as UTC. Our use case is to first call format_iso_from_string to make sure the string is valid date followed by format_iso_datetime to still return back a string (seedef _validate_parse_datetime
). If a string is passed '2011-11-04T00:05:23+05:00', we get back '2011-11-04T00:05:23Z'. I think we should not be doing 'symmetrical conversion' here but I did not want to go outside of the scope of my story to address this (comments are welcome)