Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: simplify task deserialization code, don't deserialize resources when orjson fails #257

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading