Skip to content

Commit

Permalink
Fix query error
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Oct 4, 2023
1 parent d454f48 commit 06b3274
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from flask_appbuilder.security.sqla.models import User
from flask_babel import lazy_gettext as _
from jinja2.exceptions import TemplateError
from sqlalchemy import and_, Column, or_, UniqueConstraint
from sqlalchemy import and_, Column, dialects, or_, UniqueConstraint
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import Mapper, Session, validates
from sqlalchemy.orm.exc import MultipleResultsFound
Expand Down Expand Up @@ -1608,6 +1608,10 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
columns = [col for col in columns if col != utils.DTTM_ALIAS]
dttm_col = columns_by_name.get(granularity) if granularity else None

# use quoter for quoting column names
dialect = dialects.registry.load(self.db_engine_spec.engine)
quoter = dialect().identifier_preparer.quote

if need_groupby:
# dedup columns while preserving order
columns = groupby or columns
Expand All @@ -1629,7 +1633,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
)
else:
selected = validate_adhoc_subquery(
selected,
quoter(selected),
self.database_id,
self.schema,
self.db_engine_spec.engine,
Expand All @@ -1652,7 +1656,7 @@ def get_sqla_query( # pylint: disable=too-many-arguments,too-many-locals,too-ma
_sql = selected["sqlExpression"]
_column_label = selected["label"]
elif isinstance(selected, str):
_sql = selected
_sql = quoter(selected)
_column_label = selected

selected = validate_adhoc_subquery(
Expand Down

0 comments on commit 06b3274

Please sign in to comment.