Skip to content

fix: Return 400 for missing metrics in chart data preview#1376

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

fix: Return 400 for missing metrics in chart data preview#1376
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-preview-metrics-validation

Conversation

@sentry
Copy link
Copy Markdown

@sentry sentry Bot commented May 24, 2026

This PR addresses the issue where ValueError: At least one metric is required for aggregated charts was being reported as a 500 error to Sentry (DALGO-BACKEND-1W4).

Problem:
The /api/charts/chart-data-preview/ and /api/charts/chart-data-preview/total-rows/ endpoints were catching ValueError (raised when a non-table chart type was requested without metrics) with a broad except Exception block. This resulted in an HTTP 500 response and an unnecessary error log in Sentry, treating a client-side input validation issue as a server error.

Solution:

  1. Modified get_chart_data_preview to specifically catch ValueError before the general Exception handler.
  2. Modified get_chart_data_preview_total_rows to also specifically catch ValueError.
  3. For ValueError instances, an HTTP 400 (Bad Request) is now returned to the client, providing a more accurate response for invalid input.
  4. The logging level for these ValueError cases has been downgraded from error to warning to prevent them from being reported as critical issues in Sentry.

This change aligns the behavior of the chart data preview endpoints with the existing get_chart_data endpoint, which already handles ValueError in a similar manner.

Fixes DALGO-BACKEND-1W4

@sentry
Copy link
Copy Markdown
Author

sentry Bot commented May 24, 2026

Codecov Report

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

Files with missing lines Patch % Lines
ddpui/api/charts_api.py 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1376      +/-   ##
==========================================
- 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.
📢 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