fix: use configured timezone for MySQL session time_zone#2127
Merged
abondar merged 2 commits intotortoise:mainfrom Mar 3, 2026
Merged
fix: use configured timezone for MySQL session time_zone#2127abondar merged 2 commits intotortoise:mainfrom
abondar merged 2 commits intotortoise:mainfrom
Conversation
When use_tz=True, the MySQL client was using timezone.now().utcoffset() to compute the session time_zone offset. Since timezone.now() returns a UTC-aware datetime, its utcoffset() is always timedelta(0), so the session was always set to +0:00 regardless of the configured timezone. Use get_default_timezone() to obtain the configured timezone and compute the correct UTC offset from it. Fixes tortoise#2114
Member
|
@Br1an67 Hi! Check linter here please |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
abondar
pushed a commit
that referenced
this pull request
Mar 3, 2026
* fix: use configured timezone for MySQL session time_zone When use_tz=True, the MySQL client was using timezone.now().utcoffset() to compute the session time_zone offset. Since timezone.now() returns a UTC-aware datetime, its utcoffset() is always timedelta(0), so the session was always set to +0:00 regardless of the configured timezone. Use get_default_timezone() to obtain the configured timezone and compute the correct UTC offset from it. Fixes #2114 * style: fix ruff formatting in test_connection_params.py Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> (cherry picked from commit 54820ed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When
use_tz=True, the MySQL client sets the sessiontime_zoneusingtimezone.now().utcoffset(). Sincetimezone.now()returns a UTC-aware datetime, itsutcoffset()is alwaystimedelta(0), causing the session to always be set to+0:00regardless of the configured timezone (e.g.Asia/Shanghai).This PR replaces
timezone.now()withget_default_timezone()to compute the correct UTC offset from the user-configured timezone.Motivation and Context
Fixes #2114
How Has This Been Tested?
test_mysql_session_timezone_uses_configured_tzintests/backends/test_connection_params.pyUSE_TZ=TrueandTIMEZONE=Asia/Shanghai, then verifies theSET time_zonecall uses+8:00Checklist: