From 4454c16924b310d03584a1f85e4b2114ff53070b Mon Sep 17 00:00:00 2001 From: Mark Story Date: Fri, 15 Dec 2023 10:46:31 -0500 Subject: [PATCH] fix(cleanup) Convert id collections to list (#61805) pyscopg will convert lists to ARRAY[] but not other container types. Casting collections to list prevents SQL syntax errors. Fixes SENTRY-2b2x --- src/sentry/utils/query.py | 2 +- tests/sentry/utils/test_query.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/sentry/utils/query.py b/src/sentry/utils/query.py index 0af01b9102d883..bcf8b3b9f09bbd 100644 --- a/src/sentry/utils/query.py +++ b/src/sentry/utils/query.py @@ -261,7 +261,7 @@ def bulk_delete_objects( if column.endswith("__in"): column, _ = column.split("__") query.append(f"{quote_name(column)} = ANY(%s)") - params.append(value) + params.append(list(value)) else: query.append(f"{quote_name(column)} = %s") params.append(value) diff --git a/tests/sentry/utils/test_query.py b/tests/sentry/utils/test_query.py index 68a4052f78f6b2..fd600de9c69ba6 100644 --- a/tests/sentry/utils/test_query.py +++ b/tests/sentry/utils/test_query.py @@ -79,6 +79,26 @@ def test_basic(self): assert result, "Could be more work to do" assert len(UserReport.objects.all()) == 0 + def test_basic_tuple(self): + total = 10 + records = [] + for i in range(total): + records.append(self.create_userreport(project=self.project, event_id=str(i) * 32)) + + result = bulk_delete_objects(UserReport, id__in=tuple([r.id for r in records])) + assert result, "Could be more work to do" + assert len(UserReport.objects.all()) == 0 + + def test_basic_set(self): + total = 10 + records = [] + for i in range(total): + records.append(self.create_userreport(project=self.project, event_id=str(i) * 32)) + + result = bulk_delete_objects(UserReport, id__in={r.id for r in records}) + assert result, "Could be more work to do" + assert len(UserReport.objects.all()) == 0 + def test_limiting(self): total = 10 records = []