From de62b7774f24dc4b9dca3d0ae8ecab755332e7ef Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 23 Mar 2024 00:25:05 -1000 Subject: [PATCH] Reduce sqlalchemy reflection overhead at recorder setup time (#113989) --- homeassistant/components/recorder/auto_repairs/schema.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/recorder/auto_repairs/schema.py b/homeassistant/components/recorder/auto_repairs/schema.py index 2b533b79e6c..aa2fc1bb8cb 100644 --- a/homeassistant/components/recorder/auto_repairs/schema.py +++ b/homeassistant/components/recorder/auto_repairs/schema.py @@ -6,7 +6,7 @@ from collections.abc import Iterable, Mapping import logging from typing import TYPE_CHECKING -from sqlalchemy import MetaData +from sqlalchemy import MetaData, Table from sqlalchemy.exc import OperationalError from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm.attributes import InstrumentedAttribute @@ -94,9 +94,9 @@ def _validate_table_schema_has_correct_collation( with session_scope(session=instance.get_session(), read_only=True) as session: table = table_object.__tablename__ metadata_obj = MetaData() + reflected_table = Table(table, metadata_obj, autoload_with=instance.engine) connection = session.connection() - metadata_obj.reflect(bind=connection) - dialect_kwargs = metadata_obj.tables[table].dialect_kwargs + dialect_kwargs = reflected_table.dialect_kwargs # Check if the table has a collation set, if its not set than its # using the server default collation for the database