Skip to content

Commit

Permalink
fix(cleanup) Convert id collections to list (getsentry#61805)
Browse files Browse the repository at this point in the history
pyscopg will convert lists to ARRAY[] but not other container types.
Casting collections to list prevents SQL syntax errors.

Fixes SENTRY-2b2x
  • Loading branch information
markstory authored Dec 15, 2023
1 parent a2caa19 commit 4454c16
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sentry/utils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/sentry/utils/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down

0 comments on commit 4454c16

Please sign in to comment.