77import pandas as pd
88from sqlglot import exp , parse_one
99
10- from sqlmesh .core .dialect import normalize_and_quote , normalize_model_name
10+ from sqlmesh .core .dialect import normalize_and_quote , normalize_model_name , schema_
1111from sqlmesh .core .engine_adapter import EngineAdapter
1212from sqlmesh .core .snapshot import DeployabilityIndex , Snapshot , to_table_mapping
1313from sqlmesh .utils .errors import ConfigError , ParsetimeAdapterCallError
@@ -245,14 +245,11 @@ def __init__(
245245 def get_relation (
246246 self , database : t .Optional [str ], schema : str , identifier : str
247247 ) -> t .Optional [BaseRelation ]:
248- return self .load_relation (
249- self .relation_type .create (
250- database = database ,
251- schema = schema ,
252- identifier = identifier ,
253- quote_policy = self .quote_policy ,
254- )
255- )
248+ target_table = exp .table_ (identifier , db = schema , catalog = database )
249+ # Normalize before converting to a relation; otherwise, it will be too late,
250+ # as quotes will have already been applied.
251+ target_table = self ._normalize (target_table )
252+ return self .load_relation (self ._table_to_relation (target_table ))
256253
257254 def load_relation (self , relation : BaseRelation ) -> t .Optional [BaseRelation ]:
258255 mapped_table = self ._map_table_name (self ._normalize (self ._relation_to_table (relation )))
@@ -262,10 +259,11 @@ def load_relation(self, relation: BaseRelation) -> t.Optional[BaseRelation]:
262259 return self ._table_to_relation (mapped_table )
263260
264261 def list_relations (self , database : t .Optional [str ], schema : str ) -> t .List [BaseRelation ]:
265- reference_relation = self .relation_type .create (
266- database = database , schema = schema , quote_policy = self .quote_policy
267- )
268- return self .list_relations_without_caching (reference_relation )
262+ target_schema = schema_ (schema , catalog = database )
263+ # Normalize before converting to a relation; otherwise, it will be too late,
264+ # as quotes will have already been applied.
265+ target_schema = self ._normalize (target_schema )
266+ return self .list_relations_without_caching (self ._table_to_relation (target_schema ))
269267
270268 def list_relations_without_caching (self , schema_relation : BaseRelation ) -> t .List [BaseRelation ]:
271269 from sqlmesh .dbt .relation import RelationType
0 commit comments