fix(charts): handle PostgreSQL INTERVAL type in bar and pie charts

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>
This commit is contained in:
Evan Rusackas
2025-08-01 14:52:24 -07:00
parent 72d39bea85
commit 4e74dc0250
2 changed files with 28 additions and 4 deletions

View File

@@ -15,14 +15,14 @@
# specific language governing permissions and limitations
# under the License.
from datetime import datetime
from datetime import datetime, timedelta
from typing import Any, Optional
from unittest.mock import MagicMock
import pytest
from pytest_mock import MockerFixture
from sqlalchemy import column, types
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, ENUM, JSON
from sqlalchemy.dialects.postgresql import DOUBLE_PRECISION, ENUM, INTERVAL, JSON
from sqlalchemy.engine.interfaces import Dialect
from sqlalchemy.engine.url import make_url
@@ -363,3 +363,18 @@ class TestRedshiftDetection:
spec.update_params_from_encrypted_extra(database, params)
assert "pool_events" not in params
def test_interval_type_mutator() -> None:
"""
DB Eng Specs (postgres): Test INTERVAL type mutator
"""
# Test timedelta conversion
td = timedelta(days=1, hours=2, minutes=30, seconds=45)
mutator = spec.column_type_mutators[INTERVAL]
assert mutator(td) == 95445.0 # Total seconds: 1*86400 + 2*3600 + 30*60 + 45
# Test that non-timedelta values pass through unchanged
assert mutator("not a timedelta") == "not a timedelta"
assert mutator(12345) == 12345
assert mutator(None) is None