Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
export: Add check_metadata flag.
Steve Howell42ecabe967d2
diff --git a/zerver/lib/export.py b/zerver/lib/export.pyindex 742edf8dbca..24e6bed3480 100644--- a/zerver/lib/export.py+++ b/zerver/lib/export.py@@ -1455,25 +1455,31 @@ def export_files_from_s3(key = bucket.Object(bkey.key)- if "realm_id" not in key.metadata:- raise AssertionError(f"Missing realm_id in key metadata: {key.metadata}")+ """+ For very old realms we may not have proper metadata. If you really need+ an export to bypass these checks, flip the following flag.+ """+ checking_metadata = True+ if checking_metadata:+ if "realm_id" not in key.metadata:+ raise AssertionError(f"Missing realm_id in key metadata: {key.metadata}")- if "user_profile_id" not in key.metadata:- raise AssertionError(f"Missing user_profile_id in key metadata: {key.metadata}")+ if "user_profile_id" not in key.metadata:+ raise AssertionError(f"Missing user_profile_id in key metadata: {key.metadata}")- if int(key.metadata["user_profile_id"]) not in user_ids:- continue+ if int(key.metadata["user_profile_id"]) not in user_ids:+ continue- # This can happen if an email address has moved realms- if key.metadata["realm_id"] != str(realm.id):- if email_gateway_bot is None or key.metadata["user_profile_id"] != str(- email_gateway_bot.id- ):- raise AssertionError(- f"Key metadata problem: {key.key} / {key.metadata} / {realm.id}"- )- # Email gateway bot sends messages, potentially including attachments, cross-realm.- print(f"File uploaded by email gateway bot: {key.key} / {key.metadata}")+ # This can happen if an email address has moved realms+ if key.metadata["realm_id"] != str(realm.id):+ if email_gateway_bot is None or key.metadata["user_profile_id"] != str(+ email_gateway_bot.id+ ):+ raise AssertionError(+ f"Key metadata problem: {key.key} / {key.metadata} / {realm.id}"+ )+ # Email gateway bot sends messages, potentially including attachments, cross-realm.+ print(f"File uploaded by email gateway bot: {key.key} / {key.metadata}")record = _get_exported_s3_record(bucket_name, key, processing_emoji)