Skip to content

Commit

Permalink
Fix: simplify task deserialization, don't deserialize resources when …
Browse files Browse the repository at this point in the history
…orjson fails
  • Loading branch information
psrok1 committed May 14, 2024
1 parent 5ca095a commit c201501
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 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, 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,7 @@ 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, parse_resources=parse_resources)
for task_data in self.redis.mget(chunk)
if task_data is not None
)
Expand Down
2 changes: 1 addition & 1 deletion karton/core/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def unserialize_resources(value: Any) -> Any:
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 = json.loads(data)

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

0 comments on commit c201501

Please sign in to comment.