-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Description
Bug description
Description
We are experiencing an issue in Apache Superset where custom SQL defined inside a metric is automatically modified after saving, causing incorrect results.
Specifically, whitespace inside string literals is removed, which changes the logic of the condition and leads to filters becoming inactive or returning incorrect values.
Example
Original metric SQL:
COUNT(
DISTINCT CASE
WHEN type = 'Internal'
AND "Days B/W A and S" = '1 Day (Same day)'
AND sourcetype = 'Cheque'
THEN CONCAT("ID", '-', title)
END
)
After saving the chart (or sometimes after editing/reopening), Superset automatically changes the string literal to:
'1 Day(Same day)'
Notice the space between Day and (Same day) is removed.
Actual Behavior
Superset alters the SQL inside the metric without user input.
Whitespace inside string values is removed.
As a result:
The condition no longer matches the actual column value.
Filters become inactive.
Metric values change unexpectedly.
Expected Behavior
Superset should preserve the custom SQL exactly as written, especially string literals.
No automatic formatting or modification should occur that changes query semantics.
Impact
Incorrect metric calculations
Inconsistent dashboard results
Hard-to-detect data issues after saving or reloading charts
Frequency
Occurs intermittently after saving or editing charts/metrics.
Workarounds Tried
Re-editing and re-saving the metric manually
Replacing the condition with alternative logic
(Neither provides a reliable long-term fix.)
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.9
Node version
16
Browser
Chrome
Additional context
Using Superset Version 4.1.1
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.