mirror of
https://github.com/apache/superset.git
synced 2026-05-28 19:25:20 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user