Always use UTC time for the MariaDB/MySQL session (#87583)
This commit is contained in:
parent
c05a7b29e6
commit
db503c0daa
3 changed files with 8 additions and 4 deletions
|
@ -996,7 +996,7 @@ def _migrate_columns_to_timestamp(
|
|||
text(
|
||||
"UPDATE events set time_fired_ts="
|
||||
"IF(time_fired is NULL,0,"
|
||||
"UNIX_TIMESTAMP(CONVERT_TZ(time_fired,'+00:00',@@global.time_zone))"
|
||||
"UNIX_TIMESTAMP(time_fired)"
|
||||
") "
|
||||
"where time_fired_ts is NULL "
|
||||
"LIMIT 250000;"
|
||||
|
@ -1009,10 +1009,10 @@ def _migrate_columns_to_timestamp(
|
|||
text(
|
||||
"UPDATE states set last_updated_ts="
|
||||
"IF(last_updated is NULL,0,"
|
||||
"UNIX_TIMESTAMP(CONVERT_TZ(last_updated,'+00:00',@@global.time_zone)) "
|
||||
"UNIX_TIMESTAMP(last_updated) "
|
||||
"), "
|
||||
"last_changed_ts="
|
||||
"UNIX_TIMESTAMP(CONVERT_TZ(last_changed,'+00:00',@@global.time_zone)) "
|
||||
"UNIX_TIMESTAMP(last_changed) "
|
||||
"where last_updated_ts is NULL "
|
||||
"LIMIT 250000;"
|
||||
)
|
||||
|
|
|
@ -543,6 +543,9 @@ def setup_connection_for_dialect(
|
|||
or MARIA_DB_107 <= version < MARIADB_WITH_FIXED_IN_QUERIES_107
|
||||
or MARIA_DB_108 <= version < MARIADB_WITH_FIXED_IN_QUERIES_108
|
||||
)
|
||||
|
||||
# Ensure all times are using UTC to avoid issues with daylight savings
|
||||
execute_on_connection(dbapi_connection, "SET time_zone = '+00:00'")
|
||||
elif dialect_name == SupportedDialect.POSTGRESQL:
|
||||
# Historically we have marked PostgreSQL as having slow range in select
|
||||
# but this may not be true for all versions. We should investigate
|
||||
|
|
|
@ -203,9 +203,10 @@ def test_setup_connection_for_dialect_mysql(mysql_version):
|
|||
|
||||
util.setup_connection_for_dialect(instance_mock, "mysql", dbapi_connection, True)
|
||||
|
||||
assert len(execute_args) == 2
|
||||
assert len(execute_args) == 3
|
||||
assert execute_args[0] == "SET session wait_timeout=28800"
|
||||
assert execute_args[1] == "SELECT VERSION()"
|
||||
assert execute_args[2] == "SET time_zone = '+00:00'"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue