Skip to content

fix: Handle ambiguous column names in chart queries#1384

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-ambiguous-column-names
Draft

fix: Handle ambiguous column names in chart queries#1384
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-ambiguous-column-names

Conversation

@sentry

@sentry sentry Bot commented May 26, 2026

Copy link
Copy Markdown

This PR addresses the InvalidRequestError: Ambiguous column name 'SUM(program_sequence_number)' in result set column descriptions that occurred when generating chart data.

Problem:
The error arose because the chart query builder could generate SQL queries with duplicate column aliases (e.g., two SUM(program_sequence_number) columns). This happened when multiple metrics with identical aggregation and column names (and no explicit unique aliases) were included in a chart request. SQLAlchemy's dict(row) conversion then failed to process the result set due to these ambiguous column names.

Solution:
An internal helper function, _ensure_unique_alias, has been introduced in ddpui/core/charts/charts_service.py. This function takes an alias and a set of already seen aliases, returning a unique version of the alias by appending numeric suffixes (e.g., _2, _3) if a collision is detected.

This helper is now applied at all points where metric aliases are determined and used for both SQL query generation (in build_multi_metric_query) and for constructing the column_mapping (in execute_chart_query and execute_saved_chart_query). This ensures that all generated SQL column aliases are unique, preventing the InvalidRequestError during result set processing.

Fixes DALGO-BACKEND-2FX

@sentry

sentry Bot commented May 26, 2026

Copy link
Copy Markdown
Author

Codecov Report

❌ Patch coverage is 50.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.65%. Comparing base (75cb6fd) to head (b81eea6).

Files with missing lines Patch % Lines
ddpui/core/charts/charts_service.py 50.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1384      +/-   ##
==========================================
- Coverage   58.66%   58.65%   -0.01%     
==========================================
  Files         132      132              
  Lines       15690    15706      +16     
==========================================
+ Hits         9205     9213       +8     
- Misses       6485     6493       +8     

☔ 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