Skip to content

fix(backup): Suppress verbose SQL error reporting #56583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/sentry/backup/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,18 @@ def _import(
errs = {field: error for field, error in e.message_dict.items()}
raise DjangoRestFrameworkValidationError(errs) from e

sequence_reset_sql = StringIO()

sql = StringIO()
err = StringIO()
for app in apps.get_app_configs():
management.call_command(
"sqlsequencereset", app.label, "--no-color", stdout=sequence_reset_sql
)

management.call_command("sqlsequencereset", app.label, "--no-color", stdout=sql, stderr=err)
with connection.cursor() as cursor:
cursor.execute(sequence_reset_sql.getvalue())
cursor.execute(sql.getvalue())

errored = "\n".join(
[li for li in err.getvalue().splitlines() if "No sequences found." not in li]
).strip()
if errored:
raise ValueError(f"Encountered SQL errors:\n\n {errs}")


def import_in_user_scope(
Expand Down