qleroy opened a new issue, #25786: URL: https://github.com/apache/superset/issues/25786
A clear and concise description of what the bug is. #### How to reproduce the bug 1. Go to the SQL lab and open a new query, select the default examples database 2. Click on the three-dots menu and Parameters. 3. Enter the following JSON to specify defaults values for Jinja templates ([relevant doc](https://superset.apache.org/docs/installation/sql-templating/#jinja-templates) ) ```json { "my_table": "persons" } ``` 4. Enter the following text as the query ```sql SELECT * FROM {{ my_table }} ``` Observe that you can execute the query, the context you specified in the Parameters is correctly injected because the results appear as expected. 6. Save the query as a dataset and the Fatal error is raised. ### Expected results We should be able to save the Jinja-templated query as a new virtual dataset. ### Actual results A fatal error is raised. See below the logs of the superset_app container : ``` Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/flask_appbuilder/api/__init__.py", line 110, in wraps return f(self, *args, **kwargs) File "/app/superset/views/base_api.py", line 127, in wraps raise ex File "/app/superset/views/base_api.py", line 121, in wraps duration, response = time_function(f, self, *args, **kwargs) File "/app/superset/utils/core.py", line 1526, in time_function response = func(*args, **kwargs) File "/app/superset/utils/log.py", line 255, in wrapper value = f(*args, **kwargs) File "/app/superset/views/base_api.py", line 93, in wraps return f(self, *args, **kwargs) File "/app/superset/datasets/api.py", line 315, in post new_model = CreateDatasetCommand(item).run() File "/app/superset/datasets/commands/create.py", line 50, in run dataset.fetch_metadata(commit=False) File "/app/superset/connectors/sqla/models.py", line 1247, in fetch_metadata new_columns = self.external_metadata() File "/app/superset/connectors/sqla/models.py", line 715, in external_metadata return get_virtual_table_metadata(dataset=self) File "/app/superset/connectors/sqla/utils.py", line 143, in get_virtual_table_metadata raise SupersetGenericDBErrorException(message=str(ex)) from ex superset.exceptions.SupersetGenericDBErrorException: syntax error at or near "{" LINE 1: SELECT * FROM {{ my_table }} ``` #### Screenshots If applicable, add screenshots to help explain your problem. <img width="1468" alt="sqllab preset" src="https://github.com/apache/superset/assets/9881262/9ec3091a-3439-42d9-99d3-a34ed63ab84a"> <img width="1462" alt="sqllab preset Fatal error" src="https://github.com/apache/superset/assets/9881262/d79ce035-89e3-49a1-85d2-2ae0720a8881"> ### Environment (please complete the following information): - browser type and version: Safari, Firefox, ... - superset version: Superset 3.0.0, as well as Preset Cloud ! - any feature flags active: FEATURE_FLAGS = { "ENABLE_TEMPLATE_PROCESSING": True, } ### Checklist Make sure to follow these steps before submitting your issue - thank you! - [X] I have checked the superset logs for python stacktraces and included it here as text if there are any. - [X] I have reproduced the issue with at least the latest released version of superset. - [X] I have checked the issue tracker for the same issue and I haven't found one similar. ### Additional context I followed the docs at https://superset.apache.org/docs/installation/sql-templating/#jinja-templates and the blog post https://preset.io/blog/intro-jinja-templating-apache-superset/ Note that the query is correctly executed in the SQL IDE. I had other issues with Jinja templating The issue also appears in Preset ! -- 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]
