-
Notifications
You must be signed in to change notification settings - Fork 2.9k
fix: consistent UTC timestamp handling for PostgreSQL in DatabaseSessionService #4441
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,12 +119,15 @@ def update_timestamp_tz(self) -> float: | |
| ) | ||
| return self.get_update_timestamp(is_sqlite=is_sqlite) | ||
|
|
||
| def get_update_timestamp(self, is_sqlite: bool) -> float: | ||
| """Returns the time zone aware update timestamp.""" | ||
| if is_sqlite: | ||
| # SQLite does not support timezone. SQLAlchemy returns a naive datetime | ||
| # object without timezone information. We need to convert it to UTC | ||
| # manually. | ||
| def get_update_timestamp(self, is_sqlite: bool = False) -> float: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| """Returns the update timestamp as a POSIX float. | ||
|
|
||
| Naive datetimes (returned by SQLite and PostgreSQL which use | ||
| ``TIMESTAMP WITHOUT TIME ZONE``) are interpreted as UTC. Timezone-aware | ||
| datetimes (MySQL, MariaDB) are used directly. | ||
| """ | ||
| if self.update_time.tzinfo is None: | ||
| # Naive datetimes from SQLite / PostgreSQL are stored as UTC. | ||
| return self.update_time.replace(tzinfo=timezone.utc).timestamp() | ||
| return self.update_time.timestamp() | ||
|
|
||
|
|
||
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.
The newly added constant
_DATABRICKS_DIALECTdoes not appear to be used anywhere in the project. If it's not intended for immediate use in a subsequent change, it should be removed to keep the codebase clean.