Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating SQL queries in SQL Lab not reflecting in chart instances #31956

Open
3 tasks done
thalmis-zt opened this issue Jan 22, 2025 · 3 comments
Open
3 tasks done

Updating SQL queries in SQL Lab not reflecting in chart instances #31956

thalmis-zt opened this issue Jan 22, 2025 · 3 comments
Labels
global:jinja Related to Jinja templating sqllab Namespace | Anything related to the SQL Lab

Comments

@thalmis-zt
Copy link

thalmis-zt commented Jan 22, 2025

Bug description

OBJECTIVE:
Create a chart which can be embedded in an external website. The chart should be filterable by passing filter values as url params.

STEPS FOLLOWED:
Created an sql query in SQL lab with jinja templating to allow custom url params.

SELECT rseti,course_id,state, course_name
FROM course_overview
WHERE state = '{{ url_param("state_value","238") }}' AND course_name <= '{{url_param("course_name","12")}}'

Saved the query and Hit create chart
Image

Named the chart as “Demo Chart” and saved it.
Image

Copied the embed src and pasted in a new tab to view the chart.
Image

Chart is working fine as expected, with the state_value param filter being applied.
Image

Now, suppose I wish to edit the chart at a later point, which is best done by editing the sql query itself.
To do that, I go to Charts menu in Superset UI and click on the desired chart.
Image

In chart Explore page, I select the View in SQL Lab option
Image

I modified the query , to avoid the rseti column ( as below)

SELECT course_id,state, course_name
FROM course_overview
WHERE state = '{{ url_param("state_value","238") }}' AND course_name <= '{{url_param("course_name","12")}}'

Image

Satisfied with the results, I hit Save button. Got a message saying query has been saved.
Now, I go back to the tab where the earlier embed src is used and hit refresh, expecting that the ‘rseti’ column would have been removed from there as well. But, it isnt.

Image

Screenshots/recordings

No response

Superset version

master / latest-dev

Python version

3.10

Node version

18 or greater

Browser

Chrome

Additional context

Superset logs
No errors found. Adding it in case it helps.

2025-01-22 13:04:56,717:DEBUG:superset.sql_parse:Parsing with sqlparse statement: SELECT rseti AS rseti,
superset_app | course_id AS course_id,
superset_app | state AS state,
superset_app | course_name AS course_name
superset_app | FROM
superset_app | (SELECT rseti,
superset_app | course_id,
superset_app | state,
superset_app | course_name
superset_app | FROM course_overview
superset_app | WHERE state = '263'
superset_app | AND course_name <= '12') AS virtual_table
superset_app | LIMIT 1000

"POST
/superset/log/?explode=events HTTP/1.1" 200 1 "http://localhost:8088/superset/explore/p/pP0mYgvz2Jb/?state_value=263&standalone=1&height=400"

Checklist

  • I have searched Superset docs and Slack and didn't find a solution to my problem.
  • I have searched the GitHub issue tracker and didn't find a similar bug report.
  • 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.
@dosubot dosubot bot added global:jinja Related to Jinja templating sqllab Namespace | Anything related to the SQL Lab labels Jan 22, 2025
Copy link

dosubot bot commented Jan 22, 2025

I found a similar closed issue that might be relevant to your problem. The suggested solution in that issue was to save the new virtual dataset and then sync the columns. This process is explained in a video. Additionally, the "sync columns" button is necessary, and its location is explained in the documentation [1].

The 'sync columns' button is located under the "Columns" tab within the Datasource Editor. You can find it by navigating to the "Columns" tab and looking for the button labeled "Sync columns from source" [2][3].

Try syncing the columns after saving your changes to ensure that the updated SQL query is reflected in your chart.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@rusackas
Copy link
Member

rusackas commented Jan 23, 2025

Ahh.... I think this is just workflow confusion, which maybe @kasiazjc would have ideas on how to clarify/improve.

If you had clicked "Edit dataset" instead of "View in SQL Lab" you could edit your dataset SQL directly. However, when you "view" the query in SQL lab, it's not editing the existing dataset, just taking the SQL over there to tinker with.

When you clicked the "Save" button, you probably saved the query as a Saved Query... but this again does not edit the dataset powering your chart. Instead, you'd click the little dropdown button next to the Save button and select "Save Dataset." This gives you the option to either create a NEW dataset, or find and overwrite the dataset that is/was powering your Chart.

Image

Hope that makes sense and is enough to close the issue, but maybe this is something we can iron out or make clearer?

@thalmis-zt
Copy link
Author

@rusackas Thank you for the quick response.

The approach you suggested isn't working for me. As suggested, I overwrote the dataset by clicking on the 'Save dataset' in dropdown.

Image

Image

On clicking overwrite and explore, I am redirected to the explore charts page. I do not want to create a new chart, assuming that my only requirement is to add a new column to the table chart. Since, the dataset was edited, I expect the charts consuming the dataset will automatically update.

I refreshed the page which had the chart embedding. But, the column wasn't added.

My doubt is, do we have to update the chart embed link each time I update the dataset?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
global:jinja Related to Jinja templating sqllab Namespace | Anything related to the SQL Lab
Projects
None yet
Development

No branches or pull requests

2 participants