Bug description

I am a new user to superset and i am enabling templating to add parameters to the query in the sqlLab but i pass the query link to anyone it passed without the parameters is there any way to save the parameter with the query as it is mandatory to save it with the query even i try to save it in the description but the description doesn't appear on the UI

How to reproduce the bug

  1. go to sqlLab
  2. create query with paramters
  3. save the query
  4. open the export link
  5. you won't find the paramters

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.9

Node version

16

Browser

Chrome

Additional context

No response

Checklist

  • [X] I have searched Superset docs and Slack and didn't find a solution to my problem.
  • [X] I have searched the GitHub issue tracker and didn't find a similar bug report.
  • [X] I have checked Superset's logs for errors and if I found a relevant Python stacktrace, I included it here as text in the "additional context" section.

Comment From: dosubot[bot]

To address the issue of parameters not being included when sharing a query link in Apache Superset, especially when using templating in SQL Lab, it's important to understand the mechanisms Superset provides for sharing queries. There are two main methods to share queries with parameters:

  1. Sharing via KV Store: This method is available if the ShareQueriesViaKvStore feature flag is enabled. It allows sharing a query with parameters by generating a short URL. The query and its parameters (templateParams) are stored in a key-value store, and the shared link references this stored query.

  2. Sharing Saved Queries: When a query is saved, it can be shared using a direct link that includes the savedQueryId parameter. For this method, ensure the query is saved with all necessary parameters in the templateParams field. The shared link will allow recipients to access the query along with its parameters.

To ensure your parameters are included when sharing a query link:

  • Verify that the templateParams field is correctly populated before saving or sharing the query.
  • If using the KV Store method, ensure the ShareQueriesViaKvStore feature flag is enabled.
  • Confirm that your Superset version supports these features. If not, updating to the latest version or consulting the Superset documentation may be necessary.

These steps should help in sharing query links that include all necessary parameters, facilitating recipients to view and interact with the shared queries as intended. For more detailed implementation, you can refer to the source code in the superset-frontend/src/SqlLab/components/ShareSqlLabQuery/index.tsx and the relevant migrations in the Superset GitHub repository.

#### Details **Sources** - [superset/migrations/versions/2022-10-03_17-34_deb4c9d4a4ef_parameters_in_saved_queries.py](https://github.com/apache/superset/blob/master/superset/migrations/versions/2022-10-03_17-34_deb4c9d4a4ef_parameters_in_saved_queries.py) - [superset-frontend/src/SqlLab/components/ShareSqlLabQuery/index.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/index.tsx) - [CHANGELOG/2.1.1.md](https://github.com/apache/superset/blob/master/CHANGELOG/2.1.1.md) - [CHANGELOG/3.0.0.md](https://github.com/apache/superset/blob/master/CHANGELOG/3.0.0.md) - [superset-frontend/src/SqlLab/components/SaveQuery/index.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/components/SaveQuery/index.tsx) - [CHANGELOG/2.1.0.md](https://github.com/apache/superset/blob/master/CHANGELOG/2.1.0.md)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Comment From: Hammam94

For fruther information form the network Screen Shot 2024-05-20 at 4 20 37 PM

You can see the template_params returns with null while when i saved it i checked the network and i can see the template_params has value

Comment From: dosubot[bot]

To resolve the issue with template_params not being included when sharing a query link in Apache Superset, follow these targeted steps:

  1. Correctly Set Template Parameters: Ensure you're using the TemplateParamsEditor to input your template parameters as JSON. This ensures they're correctly set for Jinja templating in your SQL queries.

  2. Serialization and Retrieval: When saving or sharing a query, the templateParams must be serialized correctly and included in the URL. Upon opening a shared query link, Superset should deserialize these parameters and load them into the SQL Lab context. This process is crucial for the parameters to be recognized and used in the shared query.

  3. Database and Migration Check: Confirm that your Superset instance includes the migration adding a template_parameters column in the saved_query table. This column is essential for storing and retrieving template parameters in saved queries, ensuring they persist when sharing query links.

  4. Debugging and Testing: If the issue persists, debug by checking the URL generation to ensure templateParams are included, and verify that upon opening the link, parameters are correctly parsed and set into the application's state. Also, ensure your error handling logic is robust to catch and report any issues with template parameters.

By ensuring the correct setup and handling of template_params, you can improve the reliability of sharing query links with parameters in Apache Superset.

#### Details **Sources** - [superset-frontend/src/SqlLab/components/TemplateParamsEditor/index.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/components/TemplateParamsEditor/index.tsx) - [superset/migrations/versions/2022-10-03_17-34_deb4c9d4a4ef_parameters_in_saved_queries.py](https://github.com/apache/superset/blob/master/superset/migrations/versions/2022-10-03_17-34_deb4c9d4a4ef_parameters_in_saved_queries.py) - [superset/sqllab/query_render.py](https://github.com/apache/superset/blob/master/superset/sqllab/query_render.py) - [superset-frontend/src/SqlLab/components/ShareSqlLabQuery/index.tsx](https://github.com/apache/superset/blob/master/superset-frontend/src/SqlLab/components/ShareSqlLabQuery/index.tsx) - [superset-frontend/src/dashboard/util/extractUrlParams.ts](https://github.com/apache/superset/blob/master/superset-frontend/src/dashboard/util/extractUrlParams.ts) - [superset-frontend/src/utils/urlUtils.ts](https://github.com/apache/superset/blob/master/superset-frontend/src/utils/urlUtils.ts) - [superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts](https://github.com/apache/superset/blob/master/superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

Comment From: Hammam94

i got this error when creating the link There was an error with your request and here is the network response Screen Shot 2024-05-21 at 8 54 11 AM

Comment From: SamraHanifCareem

The same issue is appearing for us. Following are the reproduction steps: - Write a query with some parameters - Save the query - Re-open the query using the link or edit button

Context: Saving the query is saving the template_params successfully in the database, Seems to be an issue while fetching the saved query or could have an issue with the sql_editor_saved_state

Comment From: rusackas

This has been silent for >6 months, so I'm wondering if anyone is still facing this, or if we should consider closing it out. Contributions welcome, obviously, if anyone wants to investigate a fix.