fix: Prevent invalid SQL when sorting by non-grouped columns#1370
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix: Prevent invalid SQL when sorting by non-grouped columns#1370sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
Author
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1370 +/- ##
==========================================
- Coverage 58.66% 58.64% -0.03%
==========================================
Files 132 132
Lines 15690 15696 +6
==========================================
Hits 9205 9205
- Misses 6485 6491 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a
ProgrammingErrorthat occurs when users attempt to sort chart data by a column that is neither a selected metric nor a dimension in the aggregated query.Problem:
The
apply_chart_sortingfunction incharts_service.pywould add any non-metric sort column directly to theORDER BYclause of the generated SQL. If this column was not also present in theGROUP BYclause or used in an aggregate function, PostgreSQL would raise aGroupingError. For example, sorting byfinancial_labelwhen onlystart_datewas grouped would lead to invalid SQL likeGROUP BY start_date ORDER BY financial_label.Solution:
The
apply_chart_sortingfunction has been updated to validate non-metric sort columns. Before adding a column to theORDER BYclause, it now checks if the column is either a metric alias or one of the chart's normalized dimension columns. If the sort column does not match any of these, it is skipped, and a warning is logged. This ensures that only valid columns are included in theORDER BYclause, preventing the generation of invalid SQL and resolving theGroupingError.Fixes DALGO-BACKEND-27J