mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
fix(chart): prevent chart list from failing when a datasource lacks explore_url (#38721)
This commit is contained in:
committed by
GitHub
parent
a314e5b35e
commit
fd1c423826
@@ -85,3 +85,41 @@ class TestSlice:
|
||||
"""Test id_or_uuid_filter returns correct BinaryExpression."""
|
||||
result = id_or_uuid_filter(input_value)
|
||||
assert result is not None
|
||||
|
||||
def test_datasource_url_returns_none_when_datasource_lacks_explore_url(self):
|
||||
"""datasource_url() must not raise when the datasource has no explore_url.
|
||||
|
||||
Charts whose datasource resolves to a Query (or any other type without
|
||||
explore_url) used to raise AttributeError, which caused the entire chart
|
||||
list API response to fail instead of just skipping that one chart.
|
||||
"""
|
||||
slc = Slice()
|
||||
slc.id = 1
|
||||
|
||||
# Simulate a datasource object that does NOT have explore_url (e.g. Query)
|
||||
mock_datasource = MagicMock(spec=[]) # spec=[] means no attributes at all
|
||||
slc.table = mock_datasource
|
||||
|
||||
result = slc.datasource_url()
|
||||
assert result is None
|
||||
|
||||
def test_datasource_url_returns_explore_url_when_present(self):
|
||||
"""datasource_url() returns the datasource explore_url when it exists."""
|
||||
slc = Slice()
|
||||
slc.id = 1
|
||||
|
||||
mock_table = MagicMock()
|
||||
mock_table.explore_url = "/explore/?datasource_type=table&datasource_id=1"
|
||||
slc.table = mock_table
|
||||
|
||||
result = slc.datasource_url()
|
||||
assert result == "/explore/?datasource_type=table&datasource_id=1"
|
||||
|
||||
def test_datasource_url_returns_none_when_no_datasource(self):
|
||||
"""datasource_url() returns None when there is no datasource."""
|
||||
slc = Slice()
|
||||
slc.id = 1
|
||||
slc.table = None
|
||||
|
||||
result = slc.datasource_url()
|
||||
assert result is None
|
||||
|
||||
Reference in New Issue
Block a user