Always use UTC time for the MariaDB/MySQL session (#87583)

This commit is contained in:
J. Nick Koston 2023-02-09 11:39:45 -06:00 committed by GitHub
parent c05a7b29e6
commit db503c0daa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -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;"
)

View file

@ -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

View file

@ -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(