Skip to content

Commit

Permalink
feat: Allow set_status pass in skel and no key (#31)
Browse files Browse the repository at this point in the history
Resolves:
>We could rather implement in the toolkit.set_status that you can pass a
skel, and it also reads the key from there, and you can omit the key
argument

viur-framework/viur-shop#29 (comment)
  • Loading branch information
ArneGudermann authored Nov 22, 2024
1 parent d678c39 commit ada467d
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/viur/toolkit/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def txn(_key: db.Key, _name: str, _value: float | int, _start: float | int) -> f


def set_status(
key: _KeyType,
values: dict | t.Callable[[skeleton.SkeletonInstance | db.Entity], None],
key: t.Optional[_KeyType] = None,
values: dict | t.Callable[[skeleton.SkeletonInstance | db.Entity], None] | None = None,
precondition: t.Optional[dict | t.Callable[[skeleton.SkeletonInstance | db.Entity], None]] = None,
create: dict[str, t.Any] | t.Callable[[skeleton.SkeletonInstance | db.Entity], None] | bool = False,
skel: t.Optional[skeleton.SkeletonInstance] = None,
Expand All @@ -84,11 +84,15 @@ def set_status(
If the function does not raise an Exception, all went well.
It returns either the assigned skel, or the db.Entity on success.
"""

if key is None and skel is None:
raise ValueError("No Key is provided")
elif key is None and skel is not None:
key = skel["key"]
if values is None:
raise ValueError("No values provided")
# Transactional function
def transaction() -> skeleton.SkeletonInstance | db.Entity:
exists = True

# Use skel or db.Entity
if skel:
if not skel.fromDB(key):
Expand Down

0 comments on commit ada467d

Please sign in to comment.