fix: Handle ambiguous column names in chart queries#1384
Draft
sentry[bot] wants to merge 1 commit into
Draft
Conversation
Author
Codecov Report❌ Patch coverage is
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. 🚀 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 the
InvalidRequestError: Ambiguous column name 'SUM(program_sequence_number)' in result set column descriptionsthat 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'sdict(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 inddpui/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 thecolumn_mapping(inexecute_chart_queryandexecute_saved_chart_query). This ensures that all generated SQL column aliases are unique, preventing theInvalidRequestErrorduring result set processing.Fixes DALGO-BACKEND-2FX