I have a question about this line in the sdk: <htt...
# singer-tap-development
j
I have a question about this line in the sdk: https://gitlab.com/meltano/sdk/-/blob/main/singer_sdk/helpers/_typing.py#L25. Is there a reason the timezone is hardcoded there? I have run into a situation where when I pass it a timezone aware date, i end up with a datetime like this:
2021-07-28T15:08:23+00:00+00:00
not a blocker for me cause I worked around it, but curious
a
Hi, @joshua_adeyemi. Thanks for calling this out. I believe that specific line of code is "legacy" for us and was designed to make sure the UTC timezone is inferred when not otherwise specified. We would happily accept an issue, bug report, and/or MR if you would like to improve this. (I am actually surprised this has not already been reported by another developer.)
Actually, on looking closer, I would expect
.isoformat()
to be inclusive of timezone offset, and if so, this would be a clear bug:
val.isoformat() + "+00:00"
.
@edgar_ramirez_mondragon - Could you take a look and confirm?
I see. By default, it looks like
.isoformat()
does not include timezone offset text: https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat
If I understand this correctly, parsing from text will likely work as expected. But pre-building a datetime object may have the symptom described by @joshua_adeyemi, especially when the datetime object already is timezone aware.
j
yeah, thats what i ran into. I had to do extra parsing on my date object cause of another issue I ran into. Basically one of our ingestion sources was returning the date in this format
2021-07-29T23:26:08Z+0000
, which was causing a parse error when the replication key was being retrieved
So I had to basically parse all those dates and set back to string in proper iso8601 format, which then trigged the
val.isoformat() + "+00:00"
case
a
I think there may be an expression that works in all cases, either using the Pendulum library or a version of
.isoformat()
that includes the timezone offset directly rather than as a text concatenation.
e
yup, it's a problem with naive datetimes in python:
Copy code
>>> import datetime
>>> datetime.datetime(2021, 1, 1).isoformat()
'2021-01-01T00:00:00'
>>> from pytz import timezone
>>> datetime.datetime(2021, 1, 1, tzinfo=timezone("UTC")).isoformat()
'2021-01-01T00:00:00+00:00'
we should be able to enforce tz-awareness in that function
a
Thanks, @edgar_ramirez_mondragon! Much appreciated.
@joshua_adeyemi - Do you mind logging an issue for this? Sounds like we have a path forward and it will just be a matter of prioritizing.
j