fix: resolve aggregate column names for chart sorting#1395
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 #1395 +/- ##
==========================================
- Coverage 58.66% 58.64% -0.03%
==========================================
Files 132 132
Lines 15690 15697 +7
==========================================
Hits 9205 9205
- Misses 6485 6492 +7 ☔ 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 a
ProgrammingError: (psycopg2.errors.UndefinedColumn)that occurred when sorting charts by aggregated metrics.Problem:
When the frontend sent a sort column name as an aggregation expression (e.g.,
AVG(total_revenue)), the backend'sapply_chart_sortingfunction failed to resolve it to the correct SQL alias (e.g.,A) defined in theSELECTclause. This happened becauseapply_chart_sortingonly checked againstmetric.aliasand not the aggregation expression itself. Consequently, the rawAVG(total_revenue)string was passed to the query builder, which then generated anORDER BY "AVG(total_revenue)"clause. PostgreSQL rejected this as an undefined column because"AVG(total_revenue)"was treated as a literal column name, not a reference to the aggregated value aliased as"A".Solution:
Modified
ddpui/core/charts/charts_service.pyin theapply_chart_sortingfunction. A fallback mechanism has been added: if the sort column name does not match anymetric.alias, the code now attempts a case-insensitive match against the aggregation expression patternf"{metric.aggregation}({metric.column})". Once a matching metric is found through this fallback, the existing logic correctly generates the SQL alias (e.g.,A) for theORDER BYclause, resolving theUndefinedColumnerror.Fixes DALGO-BACKEND-26D