Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

generic view function broken #13

Open
theVAX opened this issue Feb 15, 2024 · 2 comments
Open

generic view function broken #13

theVAX opened this issue Feb 15, 2024 · 2 comments
Labels
bug Something isn't working Priority: Critical This should be dealt with ASAP. It's blocking someone.

Comments

@theVAX
Copy link
Member

theVAX commented Feb 15, 2024

if you call the view()-function on a generated viur module you'll get this Error:

Traceback (most recent call last): 
File "<exec>", line 25, in <module> 
File "<exec>", line 20, in main 
File "/lib/python3.11/site-packages/viur/scriptor/module.py", line 44, in view return await viur.view(module=self._name, key=key, group=group, **kwargs)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 
File "/lib/python3.11/site-packages/viur/scriptor/viur.py", line 96, in view return ret["values"] 
~~~^^^^^^^^^^ KeyError: 'values'

I made a example script to demonstate it:

from viur.scriptor.module import user

async def main():
    userkey=""
    auser=False
    async for au in user.list({"limit":1},renderer="vi"):
        auser=au
        break
    if auser:
        print(auser)
        userview = await user.view({"key":auser["key"]})
        print (userview)
    
@sveneberth sveneberth added the bug Something isn't working label Feb 16, 2024
@ciansen
Copy link
Collaborator

ciansen commented Feb 23, 2024

Hello,

Thanks to the report, the Scriptor API "Module" class includes some built-in functions, which are:

  • add
  • view
  • list
  • preview
  • delete

These functions have a static method signature (you can check it here: https://github.com/viur-framework/viur-scriptor-api/blob/main/viur/scriptor/module.py).

The view function requires a string argument, which is the key.

from viur.scriptor.module import user
async def main():
    userkey=""
    auser=False
    async for au in user.list({"limit":1},renderer="vi"):
        auser=au
        break
    if auser:
        print(auser)
        userview = await user.view(auser["key"])
        print (userview)

@phorward
Copy link
Member

Hello @ciansen,

the problem here is totally different: The module access functions in the scriptor-api don't ever check on HTTP status codes.

This example here:

from viur.scriptor.module import user

async def main():
    userview = await user.view("self")  # works
    print(userview)
    userview = await user.view("lol")  # 404...
    print(userview)

Fails in the second case, as the api receives a JSON-parsable string containing the error message, but the status_code of 404 is never evaluated. In this case it would be correct that the result is None, and not that anything which is returned is JSON-parsed and then relied that there is a "values" key in the result.

@phorward phorward added the Priority: Critical This should be dealt with ASAP. It's blocking someone. label Feb 23, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working Priority: Critical This should be dealt with ASAP. It's blocking someone.
Projects
None yet
Development

No branches or pull requests

4 participants