Skip to content

Commit 7a0b34e

Browse files
authored
Fix: quote columns before fetching their descriptions in the UI (#3400)
1 parent fa039a5 commit 7a0b34e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

sqlmesh/core/lineage.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ def lineage(
6969
)
7070

7171

72-
def column_dependencies(context: Context, model_name: str, column: str) -> t.Dict[str, t.Set[str]]:
72+
def column_dependencies(
73+
context: Context, model_name: str, column: str | exp.Column
74+
) -> t.Dict[str, t.Set[str]]:
7375
model = context.get_model(model_name)
7476
parents = defaultdict(set)
7577

@@ -86,7 +88,9 @@ def column_dependencies(context: Context, model_name: str, column: str) -> t.Dic
8688
return dict(parents)
8789

8890

89-
def column_description(context: Context, model_name: str, column: str) -> t.Optional[str]:
91+
def column_description(
92+
context: Context, model_name: str, column: str, quote_column: bool = False
93+
) -> t.Optional[str]:
9094
"""Returns a column's description, inferring if needed."""
9195
model = context.get_model(model_name)
9296

@@ -96,7 +100,7 @@ def column_description(context: Context, model_name: str, column: str) -> t.Opti
96100
if column in model.column_descriptions:
97101
return model.column_descriptions[column]
98102

99-
dependencies = column_dependencies(context, model_name, column)
103+
dependencies = column_dependencies(context, model_name, exp.column(column, quoted=quote_column))
100104

101105
if len(dependencies) != 1:
102106
return None

web/server/api/endpoints/models.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,10 @@ def serialize_model(context: Context, model: Model, render_query: bool = False)
8282
columns = []
8383

8484
for name, data_type in columns_to_types.items():
85-
if name in model.column_descriptions:
86-
description: t.Optional[str] = model.column_descriptions[name]
87-
elif render_query:
88-
description = column_description(context, model.name, name)
89-
else:
90-
description = None
85+
description = model.column_descriptions.get(name)
86+
if not description and render_query:
87+
# The column name is already normalized in `columns_to_types`, so we need to quote it
88+
description = column_description(context, model.name, name, quote_column=True)
9189

9290
columns.append(models.Column(name=name, type=str(data_type), description=description))
9391

0 commit comments

Comments
 (0)