@@ -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,15 @@ 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
262+ target_schema = exp .Table (
263+ this = None ,
264+ db = exp .to_identifier (schema ),
265+ catalog = exp .to_identifier (database ) if database else None ,
267266 )
268- return self .list_relations_without_caching (reference_relation )
267+ # Normalize before converting to a relation; otherwise, it will be too late,
268+ # as quotes will have already been applied.
269+ target_schema = self ._normalize (target_schema )
270+ return self .list_relations_without_caching (self ._table_to_relation (target_schema ))
269271
270272 def list_relations_without_caching (self , schema_relation : BaseRelation ) -> t .List [BaseRelation ]:
271273 from sqlmesh .dbt .relation import RelationType
0 commit comments