MCPcopy Create free account
hub / github.com/celery/celery / ensure_serializable

Function ensure_serializable

celery/utils/serialization.py:80–97  ·  view source on GitHub ↗

Ensure items will serialize. For a given list of arbitrary objects, return the object or a string representation, safe for serialization. Arguments: items (Iterable[Any]): Objects to serialize. encoder (Callable): Callable function to serialize with.

(items, encoder)

Source from the content-addressed store, hash-verified

78
79
80def ensure_serializable(items, encoder):
81 """Ensure items will serialize.
82
83 For a given list of arbitrary objects, return the object
84 or a string representation, safe for serialization.
85
86 Arguments:
87 items (Iterable[Any]): Objects to serialize.
88 encoder (Callable): Callable function to serialize with.
89 """
90 safe_exc_args = []
91 for arg in items:
92 try:
93 encoder(arg)
94 safe_exc_args.append(arg)
95 except Exception: # pylint: disable=broad-except
96 safe_exc_args.append(safe_repr(arg))
97 return tuple(safe_exc_args)
98
99
100class UnpickleableExceptionWrapper(Exception):

Callers 4

test_json_py3Method · 0.90
test_pickleMethod · 0.90
prepare_exceptionMethod · 0.90
__init__Method · 0.85

Calls

no outgoing calls

Tested by 2

test_json_py3Method · 0.72
test_pickleMethod · 0.72