Skip to content

fix: CallDeferred with SkeletonInstance #1518

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion src/viur/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ def task():
parent = taskClient.queue_path(conf.instance.project_id, queueRegion, _queue)
logging.debug(f"{parent=}, {task=}")
taskClient.create_task(tasks_v2.CreateTaskRequest(parent=parent, task=task))

logging.info(f"Created task {func.__name__}.{func.__module__} with {args=} {kwargs=} {env=}")

global _deferred_tasks
Expand Down
18 changes: 17 additions & 1 deletion src/viur/core/utils/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ def preprocess(obj: t.Any) -> t.Any:
return tuple(ViURJsonEncoder.preprocess(value) for value in obj)

elif hasattr(obj, "__class__") and obj.__class__.__name__ == "SkeletonInstance": # SkeletonInstance
return {bone_name: ViURJsonEncoder.preprocess(obj[bone_name]) for bone_name in obj}
data = obj.dbEntity
if data is None:
data ={}
Comment on lines +50 to +52
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data = obj.dbEntity
if data is None:
data ={}
data = obj.dbEntity or {}

return {
".__entity__": ViURJsonEncoder.preprocess(dict(data)),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

db.Entity inherits from dict. I think this is obsolete, but please test.

Suggested change
".__entity__": ViURJsonEncoder.preprocess(dict(data)),
".__entity__": ViURJsonEncoder.preprocess(data),

".__key__": str(obj["key"]) if obj["key"] else None,
".__skel__": obj.kindName
}

return obj

Expand Down Expand Up @@ -80,6 +87,15 @@ def _decode_object_hook(obj: t.Any):
entity = db.Entity(db.Key.from_legacy_urlsafe(obj[".__key__"]) if obj[".__key__"] else None)
entity.update(obj[".__entity__"])
return entity
elif len(obj) == 3 and all(k in obj for k in (".__entity__", ".__key__", ".__skel__")):
from viur.core.skeleton.utils import skeletonByKind
skel = skeletonByKind(obj[".__skel__"])()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a subskel of a given kind was provided? This won't work.

entity = db.Entity()
if obj[".__key__"]:
entity.key = db.Key.from_legacy_urlsafe(obj[".__key__"])
entity.update(obj[".__entity__"])
skel |= entity
return skel

return obj

Expand Down
Loading