:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(baserow): handle non-JSON table listing responses (#79361)
Tom Owers11ff8e7b9e9f
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/baserow.py b/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/baserow.pyindex 0e0f3713fb9d..3385c1cb4bf2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/baserow.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/baserow.py@@ -221,7 +221,14 @@ def list_tables(base_url: Optional[str], database_token: str) -> list[dict[str,f"{base}/api/database/tables/all-tables/", timeout=REQUEST_TIMEOUT_SECONDS)response.raise_for_status()- tables = response.json()+ try:+ tables = response.json()+ except requests.exceptions.JSONDecodeError:+ # A user-supplied host can answer 2xx (or a redirect the no-redirect session leaves+ # unfollowed) with an empty or HTML body; surface a clear reason, not a raw decode error.+ raise ValueError(+ "Baserow returned an unexpected response when listing tables. Check that the instance URL points to your Baserow API."+ )if not isinstance(tables, list):raise ValueError("Unexpected response from Baserow when listing tables")return tablesdiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/tests/test_baserow.py b/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/tests/test_baserow.pyindex 3f8ad599a928..a0c15f44f2e5 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/tests/test_baserow.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/baserow/tests/test_baserow.py@@ -16,6 +16,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.baserow.ba_read_capped,baserow_rows_source,check_table_read_permission,+ list_tables,normalize_base_url,resolve_table_id,)@@ -181,6 +182,26 @@ class TestCheckTableReadPermission:assert (reason is not None) is expects_reason+class TestListTables:+ @pytest.mark.parametrize(+ ("status_code", "body"),+ [+ (302, b""), # a redirect the no-redirect session leaves unfollowed: empty body+ (200, b"<html>not the API</html>"), # wrong URL / proxy returns an HTML page+ ],+ )+ def test_non_json_response_raises_clear_error(self, status_code: int, body: bytes) -> None:+ response = Response()+ response.status_code = status_code+ response._content = body+ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.baserow.baserow._get_session"+ ) as mock_session:+ mock_session.return_value.get.return_value = response+ with pytest.raises(ValueError, match="unexpected response"):+ list_tables(None, "tok")++def _streamed_response(chunks: list[bytes], status_code: int = 200) -> Response:resp = Response()resp.status_code = status_code