Skip to content

Conversation

@utnapischtim
Copy link
Contributor

  • with that it is possible to solve the datetime.utcnow DeprecationWarnings

@utnapischtim utnapischtim force-pushed the add-utcdatetime-type branch 2 times, most recently from 77dae3f to 6e8950b Compare December 16, 2024 21:18
def process_bind_param(self, value, dialect):
"""Process value storing into database."""
if isinstance(value, datetime):
return value.replace(tzinfo=None)
Copy link
Member

Choose a reason for hiding this comment

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

minor: I think here we should also check that value.tzinfo in (None, timezone.utc), and only in that case proceed. I would even go as far as raising an exception if it's not the case, since implicitly dropping the timezone info (or converting from local to UTC) is the behavior we want to avoid.

Needs to be tested in a couple of complex modules first (e.g. invenio-rdm-records), but I have a feeling that it'll also help us to catch some datetime-related bugs :)

)
raise ValueError(msg)

return value.replace(tzinfo=None)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

so it should be tzinfo=timezone.utc.

even if we are not storing utc (aka "+00:00") explicitly in the database, we assume it is utc and to be explicit what we retrieve from the database should be always explicitly utc (aka "+00:00")

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