diff --git a/posthog/temporal/batch_exports/batch_exports.py b/posthog/temporal/batch_exports/batch_exports.py index 1b8faf19e482e..8d85d1174fb74 100644 --- a/posthog/temporal/batch_exports/batch_exports.py +++ b/posthog/temporal/batch_exports/batch_exports.py @@ -902,6 +902,14 @@ async def finish_batch_export_run(inputs: FinishBatchExportRunInputs) -> None: for key, value in dataclasses.asdict(inputs).items() if key not in not_model_params and value is not None } + + latest_error = update_params.get("latest_error", None) + if latest_error is not None and isinstance(latest_error, str): + # NUL (\x00) bytes are not allowed in PostgreSQL, so we replace them from + # the free text field `latest_error`. + latest_error = latest_error.replace("\x00", "") + update_params["latest_error"] = latest_error + batch_export_run = await database_sync_to_async(update_batch_export_run)( run_id=uuid.UUID(inputs.id), finished_at=dt.datetime.now(dt.UTC),