Skip to content

fix: Validate chart sort columns to prevent BigQuery ORDER BY errors#1387

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/dalgo-backend-29g-chart-sort-validation
Draft

fix: Validate chart sort columns to prevent BigQuery ORDER BY errors#1387
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/dalgo-backend-29g-chart-sort-validation

Conversation

@sentry

@sentry sentry Bot commented May 27, 2026

Copy link
Copy Markdown

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 the ORDER BY clause. 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 via normalize_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

@sentry

sentry Bot commented May 27, 2026

Copy link
Copy Markdown
Author

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.64%. Comparing base (75cb6fd) to head (b4881ac).

Files with missing lines Patch % Lines
ddpui/core/charts/charts_service.py 0.00% 6 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants