Skip to content

Commit de5b777

Browse files
authored
fix(backup): Suppress verbose SQL error reporting (#56583)
1 parent 6abbccf commit de5b777

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/sentry/backup/imports.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -167,15 +167,18 @@ def _import(
167167
errs = {field: error for field, error in e.message_dict.items()}
168168
raise DjangoRestFrameworkValidationError(errs) from e
169169

170-
sequence_reset_sql = StringIO()
171-
170+
sql = StringIO()
171+
err = StringIO()
172172
for app in apps.get_app_configs():
173-
management.call_command(
174-
"sqlsequencereset", app.label, "--no-color", stdout=sequence_reset_sql
175-
)
176-
173+
management.call_command("sqlsequencereset", app.label, "--no-color", stdout=sql, stderr=err)
177174
with connection.cursor() as cursor:
178-
cursor.execute(sequence_reset_sql.getvalue())
175+
cursor.execute(sql.getvalue())
176+
177+
errored = "\n".join(
178+
[li for li in err.getvalue().splitlines() if "No sequences found." not in li]
179+
).strip()
180+
if errored:
181+
raise ValueError(f"Encountered SQL errors:\n\n {errs}")
179182

180183

181184
def import_in_user_scope(

0 commit comments

Comments
 (0)