Applies the three suggestions from #34513 review:
1. Drop the dead `isinstance(v, (int, float))` branch. psycopg2 and
psycopg3 always hand INTERVAL columns back as datetime.timedelta;
the numeric branch was unreachable in practice and was creating
false confidence in the tests covering it.
2. Move `_normalize_interval` from a `@staticmethod` on the class to a
module-level function. The previous form required
`INTERVAL: _normalize_interval.__func__ # type: ignore[attr-defined]`
to extract the underlying function from the staticmethod descriptor
inside the class body. Module-level lets `column_type_mutators`
reference the function directly — no `__func__`, no suppress.
3. Add a `logger.warning(...)` to the defensive return-None path so a
future driver surfacing something other than timedelta gets logged
rather than silently dropped.
Test updates: the numeric/bool assertions that exercised the removed
branch now exercise the defensive return-None path instead (same
expectations, but for the right reason).
- Extract lambda to named `_normalize_interval` method for testability
- Return None for NULL values to preserve NULL semantics (not 0)
- Exclude bool from numeric branch (bool is subclass of int in Python)
- Return None for unconvertible types to avoid mixed-type columns
- Add tests for zero duration, negative intervals, and bool handling
- Add INTERVAL to column spec test (NUMERIC type)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Changed INTERVAL values to be converted to milliseconds instead of
seconds, enabling users to use Superset's built-in "DURATION" number
format for human-readable display (e.g., "1d 2h 30m 45s" instead of
raw numeric values like "95445000").
This addresses the review feedback about making interval values more
user-friendly in charts while maintaining numeric operations.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Enhanced mutator to handle multiple PostgreSQL INTERVAL formats
- Added support for timedelta, numeric, None, and string values
- Improved test coverage with comprehensive test cases
- Added documentation explaining the mutator's purpose
Addresses review comments from @korbit-ai and @giftig
PostgreSQL INTERVAL types were causing bar and pie charts to fail rendering when used as metrics. This fix converts INTERVAL values (timedelta objects) to numeric seconds so they can be properly displayed in charts.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>