zhaoyongjie commented on a change in pull request #15502:
URL: https://github.com/apache/superset/pull/15502#discussion_r663712394



##########
File path: superset/connectors/sqla/models.py
##########
@@ -404,9 +404,14 @@ class SqlMetric(Model, BaseMetric):
     )
     export_parent = "table"
 
+    def get_template_processor(self, **kwargs: Any) -> BaseTemplateProcessor:
+        return self.table.get_template_processor()
+
     def get_sqla_col(self, label: Optional[str] = None) -> Column:
         label = label or self.metric_name
-        sqla_col: ColumnClause = literal_column(self.expression)
+        sqla_col: ColumnClause = literal_column(
+            self.get_template_processor().process_template(self.expression)
+        )

Review comment:
       It is not recommended to add the new instance 
method(get_template_processor) here.
   
   ```suggestion
       def get_sqla_col(self, label: Optional[str] = None) -> Column:
           label = label or self.metric_name
   
           tp = self.table.get_template_processor()
           sqla_col = literal_column(tp.process_template(self.expression))
           return self.table.make_sqla_column_compatible(sqla_col, label)
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to