: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): explain a realtime database url with no database behind it (#111513)
Tom Owers16b14b40c736
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 327d1e4e4ce5..608e3b0bb168 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@@ -56,6 +56,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.firebase.sOAUTH_SCOPES,REALTIME_DATABASE_HOST_SUFFIXES,REALTIME_DATABASE_KEY_COLUMN,+ REALTIME_DATABASE_NOT_FOUND_ERROR,REALTIME_DATABASE_PAGE_SIZE,REALTIME_DATABASE_PATH_COLUMN,REALTIME_DATABASE_VALUE_COLUMN,@@ -823,7 +824,12 @@ def iter_realtime_database(params: dict[str, Any] = {"orderBy": '"$key"', "limitToFirst": REALTIME_DATABASE_PAGE_SIZE}if cursor is not None:params["startAt"] = json.dumps(cursor)- payload = _request(session, tokens, "GET", url, params=params)+ try:+ payload = _request(session, tokens, "GET", url, params=params)+ except requests.HTTPError as e:+ if e.response is not None and e.response.status_code == 404:+ raise FirebaseConfigError(REALTIME_DATABASE_NOT_FOUND_ERROR) from e+ raisechildren = _realtime_database_children(payload)if children is None:diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/settings.pyindex 18092dcb4384..82921b821994 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/settings.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/settings.py@@ -147,6 +147,10 @@ REDACTED_AUTH_USER_FIELDS: Final[frozenset[str]] = frozenset({"passwordHash", "s# pointing the minted Google access token at an arbitrary server.REALTIME_DATABASE_HOST_SUFFIXES: Final[tuple[str, ...]] = (".firebaseio.com", ".firebasedatabase.app")+# A Realtime Database answers 404 only when no database instance lives at the host. A missing path+# under a real instance answers 200 with `null`, so a 404 always means the configured URL is wrong.+REALTIME_DATABASE_NOT_FOUND_ERROR: Final[str] = "Firebase has no Realtime Database at the configured URL"+def firestore_table_name(collection_id: str) -> str:"""Table name for one root-level Firestore collection (`rooms`)."""diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/source.pyindex 2fbc74426b18..f21db1dc3992 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/firebase/source.py@@ -29,6 +29,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.firebase.sAPI_VERSION,DEFAULT_DATABASE_ID,FIRESTORE_INDEX_REQUIRED_ERROR,+ REALTIME_DATABASE_NOT_FOUND_ERROR,RESPONSE_TOO_LARGE_ERROR,parse_realtime_database_paths,)@@ -65,6 +66,7 @@ class FirebaseSource(ResumableSource[FirebaseSourceConfig, FirebaseResumeConfig]"private key could not be read": "The uploaded key file does not contain a usable private key. Upload the JSON key exactly as Google generated it.","401 Client Error: Unauthorized": "Firebase rejected the access token. The service account key may have been revoked — please reconnect.","403 Client Error: Forbidden": "This service account cannot read the requested Firebase data. Grant it the Firebase Viewer, Cloud Datastore Viewer, or Firebase Realtime Database Viewer role.",+ REALTIME_DATABASE_NOT_FOUND_ERROR: "No Realtime Database exists at this source's URL. Copy the URL from the Firebase console's Realtime Database page into the source, then re-enable the sync.",RESPONSE_TOO_LARGE_ERROR: "Firebase returned a page too large to process. Reduce the size of the documents in this collection or path, then re-run the sync.",# Firestore indexes every field on its own by default, so this only appears once someone# exempts the chosen field from indexing. Google's message carries a console link thatdiff --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 7eed56ed1e35..dcfd63ccf5fe 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@@ -12,6 +12,7 @@ import jwtimport requestsfrom structlog.types import FilteringBoundLogger+from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import error_message_matchesfrom products.warehouse_sources.backend.temporal.data_imports.sources.firebase.firebase import (AccessTokenProvider,FirebaseAuthError,@@ -59,6 +60,7 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.firebase.sREALTIME_DATABASE_VALUE_COLUMN,RESPONSE_TOO_LARGE_ERROR,)+from products.warehouse_sources.backend.temporal.data_imports.sources.firebase.source import FirebaseSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.firebase.tests.conftest import (PUBLIC_KEY_PEM,TOKEN_PAYLOAD,@@ -963,6 +965,36 @@ class TestRealtimeDatabase:assert [row[REALTIME_DATABASE_KEY_COLUMN] for row in batches[0]] == ["0", "2"]+ def test_missing_database_stops_with_a_message_that_omits_the_url(self, logger: FilteringBoundLogger) -> None:+ url = "https://demo-project.firebaseio.com"+ session = FakeSession(+ request_responses=[+ FakeResponse(status_code=404, payload={"error": "404 Not Found"}, url=f"{url}/rooms.json")+ ],+ post_responses=[FakeResponse(payload=TOKEN_PAYLOAD)],+ )++ with pytest.raises(FirebaseConfigError) as exc_info:+ list(+ iter_realtime_database(+ session.as_session(),+ token_provider(session),+ credentials(realtime_database_url=url),+ "rooms",+ FakeResumeManager(),+ logger,+ )+ )++ matches = [+ message+ for pattern, message in FirebaseSource().get_non_retryable_errors().items()+ if error_message_matches(str(exc_info.value), [pattern])+ ]+ assert matches and matches[0] is not None+ assert "Realtime Database" in matches[0]+ assert "demo-project" not in matches[0]+def test_missing_url_is_a_config_error(self, logger: FilteringBoundLogger) -> None:session = FakeSession(post_responses=[FakeResponse(payload=TOKEN_PAYLOAD)])