Skip to content

fix: chart preview aggregation with pagination and sorting#1385

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-preview-pagination-sort
Draft

fix: chart preview aggregation with pagination and sorting#1385
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-preview-pagination-sort

Conversation

@sentry

@sentry sentry Bot commented May 26, 2026

Copy link
Copy Markdown

This PR addresses issue DALGO-BACKEND-26C, where users encountered a ProgrammingError: UndefinedColumn when viewing chart data previews with pagination and sorting applied to aggregated metrics (e.g., COUNT(*)).

Root Cause:
The build_chart_query function in charts_service.py was structured such that when pagination was enabled, it would wrap the base table in a SELECT * subquery. However, the subsequent logic responsible for adding aggregation columns (like COUNT(*) AS "count_all_Total Count") and GROUP BY clauses was nested within the else block (the non-paginated path). This meant that for paginated queries, no aggregation columns were ever added to the main query.

When chart-level sorting was then applied, it would correctly translate the user-facing metric alias (e.g., "Total Count") into its internal SQL alias (e.g., "count_all_Total Count") and attempt to ORDER BY this column. Since the column did not exist in the SELECT clause of the paginated query, a ProgrammingError: UndefinedColumn occurred.

Solution:
To fix this, the chart-type-specific query building logic (which includes adding dimensions, metrics, and grouping) has been un-indented from the else block. This ensures that this core aggregation and column selection logic is applied universally, regardless of whether the initial data source is the raw table or a paginated subquery. As a result, when pagination is enabled, the aggregation columns will now be correctly added to the query, allowing sorting by these columns to succeed.

Fixes DALGO-BACKEND-26C

@sentry

sentry Bot commented May 26, 2026

Copy link
Copy Markdown
Author

Codecov Report

❌ Patch coverage is 25.42373% with 44 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.66%. Comparing base (75cb6fd) to head (94e7db1).

Files with missing lines Patch % Lines
ddpui/core/charts/charts_service.py 25.42% 44 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1385   +/-   ##
=======================================
  Coverage   58.66%   58.66%           
=======================================
  Files         132      132           
  Lines       15690    15690           
=======================================
  Hits         9205     9205           
  Misses       6485     6485           

☔ 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