You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2021/07/05 13:46:52 UTC

[GitHub] [superset] guydou commented on a change in pull request #15502: feat: supporting jinja templating in saved metrics

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



##########
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:
       Got it, 
   
   Fixed the code, 
   
   Why it is not recommended to have new instance method? I am asking only yo expand my knowledge
   
   Thanks 




-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org