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

Send UTC TZ for mod creation timestamps #265

Merged
merged 2 commits into from
May 26, 2020

Conversation

HebaruSan
Copy link
Contributor

@HebaruSan HebaruSan commented May 22, 2020

Problem

As noted in Discord during review of KSP-CKAN/CKAN#3059, the timestamps from #195 don't indicate timezones. Technically this means they're in "local" time, whatever that means for a server/client interaction.

Cause

We just return created from the database, which is generated by datetime.now, which does not include the timezone:

self.created = datetime.now()

It's not clear whether the timezone can be saved to the db anyway, though. At least one comment on StackExchange suggested it couldn't. So we can add it at load instead.

Changes

Now we set the TZ to UTC.

@HebaruSan HebaruSan added Type: Improvement Area: Backend Related to the Python code that runs inside gunicorn Priority: Low Status: Ready labels May 22, 2020
@HebaruSan HebaruSan requested a review from DasSkelett May 22, 2020 18:36
Copy link

@Xinayder Xinayder left a comment

Choose a reason for hiding this comment

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

I feel like this is just a workaround. If we want to fix the problem, you should change

self.created = datetime.now()

to datetime.utcnow() to return the UTC date.

Obviously it would apply to newly created mods only, so it would need your change as well to convert the current mods to UTC.

@HebaruSan
Copy link
Contributor Author

@RockyTV are you sure that would save to the db? I saw reports that PostgreSQL doesn't save the TZ.

@DasSkelett
Copy link
Member

DasSkelett commented May 25, 2020

Looks like Postgres would support timezones:
grafik

I think we could use it by changing this line to created = Column(DateTime(timezone=true)):

created = Column(DateTime)

https://docs.sqlalchemy.org/en/13/core/type_basics.html#sqlalchemy.types.DateTime

This section also says the following, not sure what it means exactly:

For timezone support, use at least the TIMESTAMP datatype, if not the dialect-specific datatype object.

@HebaruSan
Copy link
Contributor Author

@DasSkelett I think that's another branch, that line looks a bit different on alpha:

created = Column(DateTime, default=datetime.now)

... which goes back to the discussion about having to use a lambda. And I don't want to get into that with fourteen other instances of this for other fields in that ifle.

@DasSkelett
Copy link
Member

Okay I see. Then let's stay with saving the local time (which fortunately is UTC), and converting it when handing it out via API, as your PR does currently.

If we want to, we can clean this up later, all instances of this at once, with a data migration and so on.

Copy link
Member

@DasSkelett DasSkelett left a comment

Choose a reason for hiding this comment

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

Let's try it. Not 100% sure if netkan will convert +00:00 to Z to match mods from other APIs, but I think so.
We should give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Backend Related to the Python code that runs inside gunicorn Priority: Low Status: Ready Type: Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants