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

feat: Skeleton.patch() for transactional read/write #1267

Merged
merged 27 commits into from
Oct 15, 2024

Conversation

phorward
Copy link
Member

@phorward phorward commented Sep 24, 2024

Provides a Skeleton.patch() function based on viur.toolkit.db.set_status().

This improves the Skeleton API to a better and more integrated CRUD-API (Create-Read-Update-Delete). It also introduces a ReadFromClientException that can be raised internally for client parsing error reporting.

This pull request is part of #630 and a follow-up on #1264, which should be was merged first.

This is also an alternative replacement on #991.

It either now returns the skeleton or None on error.
The truthy test works the same way as before.
Will use `skel["key"]` instead.
The key parameter allows to provide a different key for the given operation.
This might safe one more line of assignment code required before.

Also refactors Skeleton.delete() with its double db.Get()
This is a "hackish", but working way to stay backward compatible with legacy code and still integrate existing fromDB/toDB-functionality into the new read/write-API.
Drafting new `Skeleton.update()` function based on `viur.toolkit.db.set_status()`.
This function replaces the existing Skeleton.update() which should provide a dict-like behavior. For this case, the `|`- and `|=`-operators should be used. Because Skelton/SkeletonInstance is not a dict, it should provide correct CRUD functinality.

This pull request is part of viur-framework#630 and a follow-up on viur-framework#1264, which should be merged first.
@phorward phorward added feature New feature or request Priority: High After critical issues are fixed, these should be dealt with before any further issues. viur-meeting Issues to discuss in the next ViUR meeting breaking-changes This PR causes breaking changes labels Sep 24, 2024
@phorward phorward changed the base branch from main to develop September 24, 2024 22:18
@phorward phorward changed the title Feat skeleton.update feat: Skeleton.update() transactional read/write Sep 24, 2024
@phorward phorward added this to the ViUR-core v3.7 milestone Sep 24, 2024
@phorward phorward removed the viur-meeting Issues to discuss in the next ViUR meeting label Sep 30, 2024
@phorward phorward marked this pull request as ready for review October 1, 2024 11:14
... and reset previous implementration of SkeletonInstance.update().
This pull request makes the pull request fully backward-compatible again.
@phorward phorward changed the title feat: Skeleton.update() transactional read/write feat: Skeleton.edit() for transactional read/write Oct 2, 2024
@phorward phorward removed the breaking-changes This PR causes breaking changes label Oct 2, 2024
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Show resolved Hide resolved
phorward pushed a commit that referenced this pull request Oct 10, 2024
The language value needs to be a `list` as default value, not `None`.

A simple add failed already on unserialize:
```py
skel = ExampleSkel()
skel.write()
```


```py
[2024-10-10 02:06:18,911] viur/core/skeleton.py:1208 [ERROR] Failed to serialize Test_Bone_select_multi_lang <viur.core.bones.select.SelectBone object at 0x7fd69253ee40> {'de': None, 'en': None}
[2024-10-10 02:06:18,947] viur/core/request.py:331 [ERROR] ViUR has caught an unhandled exception!
[2024-10-10 02:06:18,947] viur/core/request.py:332 [ERROR] 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/.../deploy/viur/core/request.py", line 306, in _process
    self._route(path)
  File "/.../deploy/viur/core/request.py", line 565, in _route
    res = caller(*self.args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../deploy/viur/core/module.py", line 301, in __call__
    return self._func(self._instance, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../deploy/modules/example.py", line 208, in test_add1
    assert skel.write()
           ^^^^^^^^^^^^
  File "/.../deploy/viur/core/skeleton.py", line 1400, in write
    key, skel, change_list, is_add = db.RunInTransaction(__txn_write, skel)
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "src/viur/datastore/transport.pyx", line 819, in viur.datastore.transport.RunInTransaction
  File "src/viur/datastore/transport.pyx", line 816, in viur.datastore.transport.RunInTransaction
  File "/.../deploy/viur/core/skeleton.py", line 1206, in __txn_write
    bone.serialize(skel, bone_name, True)
  File "/.../deploy/viur/core/bones/base.py", line 776, in serialize
    for singleValue in newVal[language]:
                       ~~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not iterable
```

Discovered during testing
#1267
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
@phorward phorward changed the title feat: Skeleton.edit() for transactional read/write feat: Skeleton.patch() for transactional read/write Oct 14, 2024
@phorward phorward removed the viur-meeting Issues to discuss in the next ViUR meeting label Oct 14, 2024
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Outdated Show resolved Hide resolved
src/viur/core/skeleton.py Show resolved Hide resolved
@phorward phorward merged commit 10b538b into viur-framework:develop Oct 15, 2024
3 checks passed
@phorward phorward deleted the feat-Skeleton.update branch October 15, 2024 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request Priority: High After critical issues are fixed, these should be dealt with before any further issues.
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

3 participants