Skip to content

Commit 2618428

Browse files
authored
feat(taskworker) Tighten pickle checks (#91735)
Don't allow frozenset as it cannot be json encoded by orjson. dict, list, tuple are handled by earlier branches and don't need to be in the stdlib check.
1 parent 82444f9 commit 2618428

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/sentry/celery.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ def holds_bad_pickle_object(value, memo=None):
3333
bad_object = holds_bad_pickle_object(item, memo)
3434
if bad_object is not None:
3535
return bad_object
36+
return
3637
elif isinstance(value, dict):
3738
for item in value.values():
3839
bad_object = holds_bad_pickle_object(item, memo)
3940
if bad_object is not None:
4041
return bad_object
41-
42+
return
4243
if isinstance(value, models.Model):
4344
return (
4445
value,
@@ -56,7 +57,7 @@ def holds_bad_pickle_object(value, memo=None):
5657
return None
5758
elif value is None:
5859
return None
59-
elif not isinstance(value, (dict, list, str, float, int, bool, tuple, frozenset)):
60+
elif not isinstance(value, (str, float, int, bool)):
6061
return value, "do not pickle stdlib classes"
6162
return None
6263

@@ -69,9 +70,9 @@ def good_use_of_pickle_or_bad_use_of_pickle(task, args, kwargs):
6970
if bad is not None:
7071
bad_object, reason = bad
7172
raise TypeError(
72-
"Task %r was invoked with an object that we do not want "
73+
"Task %s was invoked with an object that we do not want "
7374
"to pass via pickle (%r, reason is %s) in argument %s"
74-
% (task, bad_object, reason, name)
75+
% (task.name, bad_object, reason, name)
7576
)
7677

7778

0 commit comments

Comments
 (0)