Skip to content

Commit

Permalink
Fix: simplify task deserialization code, don't deserialize resources …
Browse files Browse the repository at this point in the history
…when orjson fails (#257)
  • Loading branch information
psrok1 authored May 15, 2024
1 parent a9cf7ea commit 13857a0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions karton/core/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,7 @@ def get_tasks(
chunk_size,
)
return [
Task.unserialize(task_data, backend=self)
if parse_resources
else Task.unserialize(task_data, parse_resources=False)
Task.unserialize(task_data, backend=self, parse_resources=parse_resources)
for chunk in keys
for task_data in self.redis.mget(chunk)
if task_data is not None
Expand All @@ -465,9 +463,9 @@ def _iter_tasks(
) -> Iterator[Task]:
for chunk in chunks_iter(task_keys, chunk_size):
yield from (
Task.unserialize(task_data, backend=self)
if parse_resources
else Task.unserialize(task_data, parse_resources=False)
Task.unserialize(
task_data, backend=self, parse_resources=parse_resources
)
for task_data in self.redis.mget(chunk)
if task_data is not None
)
Expand Down
6 changes: 1 addition & 5 deletions karton/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,7 @@ def unserialize_resources(value: Any) -> Any:
if parse_resources:
task_data = json.loads(data, object_hook=unserialize_resources)
else:
try:
task_data = orjson.loads(data)
except orjson.JSONDecodeError:
# fallback, in case orjson raises exception during loading
task_data = json.loads(data, object_hook=unserialize_resources)
task_data = orjson.loads(data)

# Compatibility with Karton <5.2.0
headers_persistent_fallback = task_data["payload_persistent"].get(
Expand Down

0 comments on commit 13857a0

Please sign in to comment.