: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(bluesky): accept handles typed with a leading @ (#122547)
Tom Owers8378d66badb2
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/bluesky.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/bluesky.pyindex 43369ba8ec60..d7166acb7297 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/bluesky.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/bluesky.py@@ -235,17 +235,24 @@ def bluesky_source()+def normalize_actor(actor: str) -> str:+ # Bluesky shows handles as "@name", but the API rejects the "@" as an invalid AT identifier.+ return actor.strip().removeprefix("@")++def validate_credentials(actor: str) -> tuple[bool, str | None]:session = make_tracked_session()- response = session.get(f"{BASE_URL}/xrpc/app.bsky.actor.getProfile", params={"actor": actor})+ response = session.get(f"{BASE_URL}/xrpc/app.bsky.actor.getProfile", params={"actor": normalize_actor(actor)})if response.status_code == 200:return True, None+ # Bluesky's 400 messages name XRPC params ("Invalid app.bsky.actor.getProfile params: ..."),+ # which tell the user nothing about which field to fix.+ if response.status_code == 400:+ return False, "That handle or DID couldn't be found on Bluesky. Check the spelling and try again."+try:message = response.json().get("message")except ValueError:message = None-- if response.status_code == 400:- return False, message or "That handle or DID couldn't be found on Bluesky. Check the spelling and try again."return False, message or f"Bluesky returned an unexpected error ({response.status_code})."diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/source.pyindex db9f8a5ca361..e1a7a3def8d2 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/source.py@@ -11,6 +11,7 @@ from products.warehouse_sources.backend.facade.source_config import (from products.warehouse_sources.backend.temporal.data_imports.sources.bluesky.bluesky import (BlueskyResumeConfig,bluesky_source,+ normalize_actor,post_fanout_rows,validate_credentials as validate_bluesky_credentials,)@@ -124,18 +125,19 @@ class BlueskySource(ResumableSource[BlueskySourceConfig, BlueskyResumeConfig]):resumable_source_manager: ResumableSourceManager[BlueskyResumeConfig],inputs: SourceInputs,) -> SourceResponse:+ actor = normalize_actor(config.actor)partition_keys = PARTITION_FIELDS.get(inputs.schema_name)if inputs.schema_name in POST_FANOUT_ENDPOINTS:return SourceResponse(name=inputs.schema_name,- items=lambda: post_fanout_rows(config.actor, inputs.schema_name, resumable_source_manager),+ items=lambda: post_fanout_rows(actor, inputs.schema_name, resumable_source_manager),primary_keys=PRIMARY_KEYS[inputs.schema_name],partition_mode="datetime",partition_keys=partition_keys,)resource = bluesky_source(- actor=config.actor,+ actor=actor,endpoint=inputs.schema_name,team_id=inputs.team_id,job_id=inputs.job_id,diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/tests/test_bluesky.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/tests/test_bluesky.pyindex aaafea0a3b90..96d8acbbbf41 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/tests/test_bluesky.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bluesky/tests/test_bluesky.py@@ -21,9 +21,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.generated_class TestValidateCredentials:- def test_valid_actor(self) -> None:+ @pytest.mark.parametrize("actor", ["jay.bsky.team", "@jay.bsky.team", " jay.bsky.team "])+ def test_valid_actor(self, actor: str) -> None:with scripted_network([ScriptedResponse(json={"did": "did:plc:abc"})]) as network:- is_valid, message = validate_credentials("jay.bsky.team")+ is_valid, message = validate_credentials(actor)assert (is_valid, message) == (True, None)assert len(network.requests_log) == 1@@ -32,8 +33,18 @@ class TestValidateCredentials:)assert network.requests_log[0].method == "GET"- def test_non_json_error_body_falls_back(self) -> None:- with scripted_network([ScriptedResponse(status=400, body=b"<html>not json</html>")]):+ @pytest.mark.parametrize(+ "response",+ [+ ScriptedResponse(status=400, body=b"<html>not json</html>"),+ ScriptedResponse(+ status=400,+ json={"error": "InvalidRequest", "message": "Invalid app.bsky.actor.getProfile params: bad actor"},+ ),+ ],+ )+ def test_bad_actor_returns_actionable_message(self, response: ScriptedResponse) -> None:+ with scripted_network([response]):is_valid, message = validate_credentials("missing.bsky.social")assert is_valid is False@@ -51,8 +62,8 @@ class TestBlueskySourceResumeBehavior:"""Run Bluesky resume behavior through the source pipeline."""@staticmethod- def _driver() -> SourceDriver:- return SourceDriver(BlueskySource(), BlueskySourceConfig(actor="jay.bsky.team"))+ def _driver(actor: str = "jay.bsky.team") -> SourceDriver:+ return SourceDriver(BlueskySource(), BlueskySourceConfig(actor=actor))@pytest.mark.parametrize(("endpoint", "list_key", "item"),@@ -98,10 +109,13 @@ class TestBlueskySourceResumeBehavior:assert result.params("cursor") == [None]def test_profile_endpoint_is_a_single_page_and_never_saves_state(self) -> None:- result = self._driver().run("Profile", [ScriptedResponse(json={"did": "did:plc:1", "handle": "jay.bsky.team"})])+ result = self._driver("@jay.bsky.team").run(+ "Profile", [ScriptedResponse(json={"did": "did:plc:1", "handle": "jay.bsky.team"})]+ )assert result.raised is Noneassert len(result.requests) == 1+ assert result.params("actor") == ["jay.bsky.team"]assert result.saved_states == []def test_posts_yields_flattened_post_objects(self) -> None:@@ -159,8 +173,8 @@ POST_FANOUT_CASES = [class TestBlueskyPostFanout:@staticmethod- def _driver() -> SourceDriver:- return SourceDriver(BlueskySource(), BlueskySourceConfig(actor="jay.bsky.team"))+ def _driver(actor: str = "jay.bsky.team") -> SourceDriver:+ return SourceDriver(BlueskySource(), BlueskySourceConfig(actor=actor))@pytest.mark.parametrize(("endpoint", "list_key", "child_row", "expected_keys"), POST_FANOUT_CASES)def test_walks_every_post_and_child_page(