fix: Validate chart sort columns to prevent BigQuery ORDER BY errors#1387
Draft
sentry[bot] wants to merge 1 commit into
Draft
fix: Validate chart sort columns to prevent BigQuery ORDER BY errors#1387sentry[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 #1387 +/- ##
==========================================
- 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 DALGO-BACKEND-29G, a DatabaseError occurring when BigQuery receives an ORDER BY clause referencing a column that is neither part of the GROUP BY dimensions nor an aggregated metric.
The root cause was identified in
ddpui/core/charts/charts_service.py::apply_chart_sorting(). Previously, if a sort column was not a recognized metric alias, it was blindly treated as a dimension and passed directly to theORDER BYclause. This led to BigQuery rejecting the query if the column was not actually a grouped dimension.The fix introduces validation within
apply_chart_sorting(). Before adding a sort column to the query builder, it now checks if the column is either a metric alias or one of the chart's grouped dimensions (obtained vianormalize_dimensions(payload)). If the column does not meet these criteria, it is skipped, and a warning is logged, preventing the generation of an invalid BigQuery query.Fixes DALGO-BACKEND-29G