From 3a8343c4ad472f394644ae71a368fb4c43b59484 Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 2 May 2025 16:58:39 -0400 Subject: [PATCH 1/2] fix(taskworker) Remove bytes from relocation celery task bytes can't always be json encoded --- src/sentry/relocation/services/relocation_export/impl.py | 3 ++- src/sentry/relocation/tasks/process.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/sentry/relocation/services/relocation_export/impl.py b/src/sentry/relocation/services/relocation_export/impl.py index ac59b23a3d5479..0febd2680e06ef 100644 --- a/src/sentry/relocation/services/relocation_export/impl.py +++ b/src/sentry/relocation/services/relocation_export/impl.py @@ -3,6 +3,7 @@ # in modules such as this one where hybrid cloud data models or service classes are # defined, because we want to reflect on type annotations and avoid forward references. +import base64 import logging from datetime import UTC, datetime from io import BytesIO @@ -65,7 +66,7 @@ def request_new_export( requesting_region_name, replying_region_name, org_slug, - encrypt_with_public_key, + base64.b64encode(encrypt_with_public_key).decode("utf8"), int(round(datetime.now(tz=UTC).timestamp())), ] ) diff --git a/src/sentry/relocation/tasks/process.py b/src/sentry/relocation/tasks/process.py index 46a3275a0561ff..90328c70c71bad 100644 --- a/src/sentry/relocation/tasks/process.py +++ b/src/sentry/relocation/tasks/process.py @@ -1,5 +1,6 @@ from __future__ import annotations +import base64 import logging import re from collections import defaultdict @@ -344,7 +345,7 @@ def fulfill_cross_region_export_request( requesting_region_name: str, replying_region_name: str, org_slug: str, - encrypt_with_public_key: bytes, + encrypt_with_public_key: str, # Unix timestamp, in seconds. scheduled_at: int, ) -> None: @@ -357,6 +358,7 @@ def fulfill_cross_region_export_request( call is received with the encrypted export in tow, it will trigger the next step in the `SAAS_TO_SAAS` relocation's pipeline, namely `uploading_complete`. """ + encrypt_with_public_key = base64.b64decode(encrypt_with_public_key) logger_data = { "uuid": uuid_str, From fd6cc727e8ac9f9b80717e18b45cbdb6ad50a86e Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 2 May 2025 17:16:08 -0400 Subject: [PATCH 2/2] Fix mypy --- src/sentry/relocation/tasks/process.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sentry/relocation/tasks/process.py b/src/sentry/relocation/tasks/process.py index 90328c70c71bad..0334719711a46f 100644 --- a/src/sentry/relocation/tasks/process.py +++ b/src/sentry/relocation/tasks/process.py @@ -358,7 +358,7 @@ def fulfill_cross_region_export_request( call is received with the encrypted export in tow, it will trigger the next step in the `SAAS_TO_SAAS` relocation's pipeline, namely `uploading_complete`. """ - encrypt_with_public_key = base64.b64decode(encrypt_with_public_key) + encrypt_with_public_key_bytes = base64.b64decode(encrypt_with_public_key.encode("utf8")) logger_data = { "uuid": uuid_str, @@ -366,7 +366,7 @@ def fulfill_cross_region_export_request( "requesting_region_name": requesting_region_name, "replying_region_name": replying_region_name, "org_slug": org_slug, - "encrypted_public_key_size": len(encrypt_with_public_key), + "encrypted_public_key_size": len(encrypt_with_public_key_bytes), "scheduled_at": scheduled_at, } logger.info( @@ -398,7 +398,7 @@ def fulfill_cross_region_export_request( export_in_organization_scope( fp, - encryptor=LocalFileEncryptor(BytesIO(encrypt_with_public_key)), + encryptor=LocalFileEncryptor(BytesIO(encrypt_with_public_key_bytes)), org_filter={org_slug}, printer=LoggingPrinter(uuid_str), checkpointer=StorageBackedCheckpointExporter(