Skip to content

fix: prevent invalid bigint comparison with empty string in chart filters#1382

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-filter-numeric-empty-string
Draft

fix: prevent invalid bigint comparison with empty string in chart filters#1382
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/chart-filter-numeric-empty-string

Conversation

@sentry
Copy link
Copy Markdown

@sentry sentry Bot commented May 25, 2026

This PR addresses a DataError (psycopg2.errors.InvalidTextRepresentation) that occurred when an empty string ('') was used as a filter value for a numeric column (e.g., bigint) in chart data previews. The root cause was that the apply_chart_filters function in charts_service.py was not type-aware and directly passed filter values to SQLAlchemy, resulting in invalid SQL like WHERE total_confirmed = ''.

To fix this, the following changes were implemented in ddpui/core/charts/charts_service.py:

  • Introduced _NUMERIC_DATA_TYPES set and _is_numeric_data_type helper: To identify numeric column types.
  • Added _coerce_filter_value function: This helper now intelligently handles filter values based on their declared data_type.
    • For numeric columns, an empty string ('') is coerced to None.
    • Non-empty strings are attempted to be cast to int or float.
    • If a non-empty string cannot be cast to a numeric type, the filter is skipped with a warning log.
  • Implemented _build_eq_condition and _build_neq_condition: These functions generate IS NULL or IS NOT NULL clauses when the coerced value is None, ensuring correct SQL for null checks.
  • Integrated type-aware processing into apply_chart_filters: The data_type field from the filter configuration is now read and used to apply the coercion logic before building SQLAlchemy WHERE clauses, preventing the generation of invalid SQL.

Fixes DALGO-BACKEND-28K

@siddhant3030
Copy link
Copy Markdown
Contributor

this we can close.

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.

1 participant