Skip to content

: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.

fix(data-imports): skip trimming non-dict job_inputs (#83340)

Tom Owers4b75be5c680a
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
index cc57017c1ad9..bf55b91bd274 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/extract.py
@@ -72,7 +72,9 @@ NON_RETRYABLE_ERROR_RETRY_LIMIT = 3
async def trim_source_job_inputs(source: "ExternalDataSource") -> None:
- if not source.job_inputs:
+ # job_inputs is an EncryptedJSONField, so it can decode to a non-dict (e.g. a bare string)
+ # for a malformed source config — nothing to trim key-by-key in that case.
+ if not isinstance(source.job_inputs, dict):
return
did_update_inputs = False
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
index 3846dee5385b..fd5ae1c01420 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/common/test/test_extract.py
@@ -24,6 +24,7 @@ from products.warehouse_sources.backend.temporal.data_imports.pipelines.common.e
persist_primary_keys,
report_heartbeat_timeout,
resolve_primary_keys,
+ trim_source_job_inputs,
validate_incremental_sync,
)
from products.warehouse_sources.backend.temporal.data_imports.pipelines.core.arrow_utils import (
@@ -136,6 +137,42 @@ class TestPersistPrimaryKeys:
logger.aexception.assert_awaited_once()
+class TestTrimSourceJobInputs:
+ @parameterized.expand(
+ [
+ # A non-empty string decoded out of the EncryptedJSONField used to reach `.items()` and
+ # raise AttributeError — it must be skipped, not crash the whole import activity.
+ ("bare_string_is_skipped", "not-a-dict"),
+ ("list_is_skipped", ["a", "b"]),
+ ("none_is_skipped", None),
+ ("empty_dict_is_skipped", {}),
+ ]
+ )
+ @pytest.mark.asyncio
+ async def test_non_dict_job_inputs_is_a_noop(self, _name: str, job_inputs) -> None:
+ source = MagicMock(job_inputs=job_inputs, save=MagicMock())
+ with patch(f"{_EXTRACT_MODULE}.database_sync_to_async_pool") as pool:
+ await trim_source_job_inputs(source)
+ pool.assert_not_called()
+
+ @pytest.mark.asyncio
+ async def test_dict_job_inputs_is_trimmed_and_saved(self) -> None:
+ source = MagicMock(job_inputs={"host": " example.com ", "port": "5432"}, save=MagicMock())
+ saved = AsyncMock()
+ with patch(f"{_EXTRACT_MODULE}.database_sync_to_async_pool", return_value=saved):
+ await trim_source_job_inputs(source)
+ assert source.job_inputs["host"] == "example.com"
+ assert source.job_inputs["port"] == "5432"
+ saved.assert_awaited_once()
+
+ @pytest.mark.asyncio
+ async def test_dict_job_inputs_without_padding_does_not_save(self) -> None:
+ source = MagicMock(job_inputs={"host": "example.com"}, save=MagicMock())
+ with patch(f"{_EXTRACT_MODULE}.database_sync_to_async_pool") as pool:
+ await trim_source_job_inputs(source)
+ pool.assert_not_called()
+
+
class TestReportHeartbeatTimeoutRecording(BaseTest):
def _schema(self) -> ExternalDataSchema:
source = ExternalDataSource.objects.create(