OnroerendErfgoed / atramhasis

An online SKOS editor
http://atramhasis.readthedocs.io/
GNU General Public License v3.0
53 stars 11 forks source link

Can't add a provider with a textual id #831

Closed koenedaele closed 1 year ago

koenedaele commented 1 year ago

I try to add a new provider. If I specify an ID (eg. METAL), the provider is not created. If a leave the ID field blank, one is created with a numeric id (identical to the conceptscheme id).

The server gives the following stack trace:

2023-05-16 10:39:09,818 ERROR [atramhasis.views.exception_views][waitress-1] No row was found when one was required
Traceback (most recent call last):
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/tweens.py", line 41, in excview_tween
    response = handler(request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/router.py", line 143, in handle_request
    response = _call_view(
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/view.py", line 674, in _call_view
    response = view_callable(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/config/views.py", line 151, in __call__
    return view(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/config/views.py", line 170, in attr_view
    return view(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/config/views.py", line 196, in predicate_wrapper
    return view(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid_openapi3/__init__.py", line 133, in wrapper_view
    return view(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/viewderivers.py", line 427, in rendered_view
    result = view(context, request)
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/pyramid/viewderivers.py", line 113, in _class_requestonly_view
    response = getattr(inst, attr)()
  File "/home/koen/Projecten/python/skos/atramhasis/atramhasis/views/crud.py", line 313, in update_provider
    db_provider = provider.update_provider(
  File "/home/koen/Projecten/python/skos/atramhasis/atramhasis/json_processors/provider.py", line 36, in update_provider
    db_provider = manager.get_provider_by_id(provider_id)
  File "/home/koen/Projecten/python/skos/atramhasis/atramhasis/data/datamanagers.py", line 399, in get_provider_by_id
    ).scalar_one()
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 1208, in scalar_one
    return self._only_one_row(
  File "/home/koen/.virtualenvs/atramhasis/lib/python3.10/site-packages/sqlalchemy/engine/result.py", line 562, in _only_one_row
    raise exc.NoResultFound(
sqlalchemy.exc.NoResultFound: No row was found when one was required
2023-05-16 10:39:09,820 INFO  [pyramid_debugtoolbar][waitress-1] Squashed sqlalchemy.exc.NoResultFound at http://localhost:6543/providers/MOVIES
traceback url: http://localhost:6543/_debug_toolbar/313339393637373236333832303136/exception

Looks like a backend issue, not frontend.

koenedaele commented 1 year ago

Probably somewhat related to #833

cedrikv commented 1 year ago

example payload to reproduce:

{
   "id":"test",
   "conceptscheme_uri":"urn:x-skosprovider:testid",
   "uri_pattern":"https://id.erfgoed.net/thesauri/test/%s",
   "subject":[

   ],
   "id_generation_strategy":"NUMERIC",
   "expand_strategy":"recurse",
   "default_language":"",
   "force_display_language":""
}
vancamti commented 1 year ago

Issue seems to be frontend.

image

They perform a put instead of post when an ID is present. The post with id seems to work fine as demonstrated in the screen shot. The NoResultFound happens because you try to edit an unexisting provider. Also noticeable in the stack trace:

File "/home/koen/Projecten/python/skos/atramhasis/atramhasis/views/crud.py", line 313, in update_provider db_provider = provider.update_provider( File "/home/koen/Projecten/python/skos/atramhasis/atramhasis/json_processors/provider.py", line 36, in update_provider db_provider = manager.get_provider_by_id(provider_id)

koenedaele commented 1 year ago

In normal REST systems, a POST is without ID (telling the server to create an id itself). If you want to add something with a specific ID, a PUT is normally the correct method. Granted, we don't often allow the client to choose the ID so we might not often implement this. But normally: