: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(firebase): skip Firestore collections when the database is in Datastore mode (#85284)
Tom Owers729eea0f7b21
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/firebase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/firebase.pyindex 315b461a2cd7..d318af1f3ae1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/firebase.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/firebase.py@@ -269,8 +269,14 @@ def _request(if not response.ok:# `raise_for_status` reports status and URL only, so drain a tightly bounded prefix purely# to release the connection — the error path never needs a full page's worth of bytes.- _read_truncated_body(response, MAX_ERROR_BODY_BYTES)- response.raise_for_status()+ detail_body = _read_truncated_body(response, MAX_ERROR_BODY_BYTES)+ try:+ response.raise_for_status()+ except requests.HTTPError as e:+ # Google's structured error (status/message) lets callers tell a permanent,+ # database-configuration failure apart from a transient or unexpected one.+ e.args = (f"{e.args[0]} ({_error_detail(response, detail_body)})",)+ raiseraw = _read_capped_body(response, MAX_RESPONSE_BYTES)if not raw:@@ -577,10 +583,12 @@ def get_tables(credentials: FirebaseCredentials) -> list[str]:collection_ids = list_collection_ids(api_session, tokens, credentials)tables.extend(firestore_table_name(collection_id) for collection_id in collection_ids)except requests.HTTPError as e:- # A project with no Firestore database answers 404, and a service account without the- # Datastore role answers 403. Neither should hide the tables the source can still read.+ # A project with no Firestore database answers 404, a service account without the+ # Datastore role answers 403, and a default database provisioned in Datastore mode+ # (rather than Native mode) answers 400 — the Documents API this source reads is+ # Native-mode only. None of these should hide the tables the source can still read.status = e.response.status_code if e.response is not None else None- if status not in (403, 404):+ if status not in (403, 404) and not (status == 400 and "datastore mode" in str(e).lower()):raiseLOGGER.warning(f"Skipping Firestore collections for Firebase project {credentials.project_id}: {status}")diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/tests/test_firebase.py b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/tests/test_firebase.pyindex ad30902d7fa4..c26c7c17ae58 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/tests/test_firebase.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/tests/test_firebase.py@@ -544,9 +544,38 @@ class TestTableDiscovery:with mock.patch(_SESSION_FACTORY, return_value=session.as_session()):assert get_tables(credentials()) == [AUTH_USERS_TABLE]- def test_other_firestore_errors_propagate(self) -> None:+ def test_datastore_mode_database_does_not_hide_the_other_tables(self) -> None:session = FakeSession(- request_responses=[FakeResponse(status_code=500, payload={"error": {"status": "INTERNAL"}})],+ request_responses=[+ FakeResponse(+ status_code=400,+ payload={+ "error": {+ "code": 400,+ "status": "FAILED_PRECONDITION",+ "message": "The Cloud Firestore API is not available for Firestore in Datastore Mode database.",+ }+ },+ )+ ],+ post_responses=[FakeResponse(payload=TOKEN_PAYLOAD)],+ )++ with mock.patch(_SESSION_FACTORY, return_value=session.as_session()):+ assert get_tables(credentials()) == [AUTH_USERS_TABLE]++ @pytest.mark.parametrize(+ "status,payload",+ [+ (500, {"error": {"status": "INTERNAL"}}),+ # A 400 for any other reason is a real, actionable failure and must not be conflated+ # with the Datastore-mode case above just because the status code matches.+ (400, {"error": {"status": "INVALID_ARGUMENT", "message": "Invalid pageToken."}}),+ ],+ )+ def test_other_firestore_errors_propagate(self, status: int, payload: dict[str, Any]) -> None:+ session = FakeSession(+ request_responses=[FakeResponse(status_code=status, payload=payload)],post_responses=[FakeResponse(payload=TOKEN_PAYLOAD)],)