acdh-oeaw / vocabseditor

Vocabseditor is a web-based tool for collaborative work on controlled vocabularies development
https://vocabseditor.acdh.oeaw.ac.at/
MIT License
23 stars 6 forks source link

Server Error 500 for POST even with admin creadentials #24

Closed abiUni closed 2 years ago

abiUni commented 3 years ago

Hi, Thank you for the quick response on my last issue! I am trying to batch-create concepts in python from a .csv file into an existing ConceptScheme using the API. As an authenticated admin user, I can GET data through the API but I am unable to POST anything due to an internal server error 500.

The error stack seems to point to the django function get_identity(identity), which is called in vocabs->models.py when setting permissions. I would be very grateful if you can point me to a solution/workaround as the manual creation of the concepts is not a feasible option. Thank you!

500
Undocumented
Error: Internal Server Error
Response body

NotUserNorGroup at /api/skosconcepts/
User/AnonymousUser or Group instance is required (got None)

Request Method: POST
Request URL: http://localhost:8000/api/skosconcepts/
Django Version: 3.1.5
Python Executable: /Users/user/opt/anaconda3/bin/python
Python Version: 3.7.9
Python Path: ['/Users/user/Desktop/vocabseditor-master', '/usr/bin/python3', '/Users/user/Desktop/vocabseditor-master', '/Users/user/opt/anaconda3/lib/python37.zip', '/Users/user/opt/anaconda3/lib/python3.7', '/Users/user/opt/anaconda3/lib/python3.7/lib-dynload', '/Users/user/.local/lib/python3.7/site-packages', '/Users/user/opt/anaconda3/lib/python3.7/site-packages']
Server time: Sat, 02 Oct 2021 10:39:01 +0000
Installed Applications:
['dal',
 'dal_select2',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'reversion',
 'guardian',
 'crispy_forms',
 'django_filters',
 'django_tables2',
 'rest_framework',
 'webpage',
 'browsing',
 'vocabs',
 'mptt',
 'drf_yasg',
 'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'reversion.middleware.RevisionMiddleware']

Traceback (most recent call last):
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/viewsets.py", line 125, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/mixins.py", line 19, in create
    self.perform_create(serializer)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/mixins.py", line 24, in perform_create
    serializer.save()
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/serializers.py", line 205, in save
    self.instance = self.create(validated_data)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/rest_framework/serializers.py", line 939, in create
    instance = ModelClass._default_manager.create(**validated_data)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/db/models/manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/db/models/query.py", line 447, in create
    obj.save(force_insert=True, using=self.db)
  File "/Users/user/Desktop/vocabseditor-master/vocabs/models.py", line 623, in save
    super(SkosConcept, self).save(*args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/mptt/models.py", line 1014, in save
    super(MPTTModel, self).save(*args, **kwargs)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 754, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/db/models/base.py", line 803, in save_base
    update_fields=update_fields, raw=raw, using=using,
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 179, in send
    for receiver in self._live_receivers(sender)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 179, in <listcomp>
    for receiver in self._live_receivers(sender)
  File "/Users/user/Desktop/vocabseditor-master/vocabs/models.py", line 810, in create_perms_concept_created_by
    assign_perm('delete_skosconcept', instance.created_by, instance)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/guardian/shortcuts.py", line 86, in assign_perm
    user, group = get_identity(user_or_group)
  File "/Users/user/opt/anaconda3/lib/python3.7/site-packages/guardian/utils.py", line 91, in get_identity
    "(got %s)" % identity)

Exception Type: NotUserNorGroup at /api/skosconcepts/
Exception Value: User/AnonymousUser or Group instance is required (got None)
Request information:
USER: admin

GET: No GET data

POST: No POST data

FILES: No FILES data
csae8092 commented 3 years ago

@zxenia do you have time to look into this issue or should I?

zxenia commented 3 years ago

@csae8092 Hi, yes I have time, I will look into it.

csae8092 commented 3 years ago

Hi @abiUni I was wondering if you could share your .csv (or parts of it) you are using to batch create concepts. Because we'd like to provide some "create concepts from csv" or "upload your csv" feature anyways, but were too lazy to think about how the source-csv could/should look like.

abiUni commented 3 years ago

Hello @csae8092, apologies for the late response, I should clarify I don't have a .csv where all SKOS fields are prefilled. Instead I have a list of keywords with definitions, which I would like to add to my vocabulary and automatically link them to external vocabularies that I query with rdflib using a python script.

csae8092 commented 2 years ago

ok, now I have to apologize for the very very late response. Thanks for the explanation. I'll close this issue as I think @zxenia fixed the broken code. But please reopen it or create another issue if the problem still exits