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

JSON import gives 500 error on certain recipes #146

Closed
RustyRin opened this issue Aug 8, 2020 · 3 comments
Closed

JSON import gives 500 error on certain recipes #146

RustyRin opened this issue Aug 8, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@RustyRin
Copy link

RustyRin commented Aug 8, 2020

Version

0.10.0

Issue

Importing a recipe from a JSON file gives 500 error

Server log:

web_recipes_1    | Traceback (most recent call last):
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
web_recipes_1    |     response = get_response(request)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
web_recipes_1    |     response = self.process_exception_by_middleware(e, request)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
web_recipes_1    |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
web_recipes_1    |     return view_func(request, *args, **kwargs)
web_recipes_1    |   File "/opt/recipes/cookbook/views/import_export.py", line 31, in import_recipe
web_recipes_1    |     recipe = sr.save()
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 230, in save
web_recipes_1    |     return super(BaseNestedModelSerializer, self).save(**kwargs)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/rest_framework/serializers.py", line 212, in save
web_recipes_1    |     self.instance = self.create(validated_data)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 258, in create
web_recipes_1    |     self.update_or_create_reverse_relations(instance, reverse_relations)
web_recipes_1    |   File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 196, in update_or_create_reverse_relations
web_recipes_1    |     raise ValidationError({field_name: errors})
web_recipes_1    | rest_framework.exceptions.ValidationError: {'steps': [{'ingredients': [{}, {}, {'food': {'name': [ErrorDetail(string='This field must be unique.', code='unique')]}}, {}, {}, {}, {}, {}, {}, {'unit': {'name': [ErrorDetail(string='This field must be unique.', code='unique')]}}]}]}
web_recipes_1    | 172.18.0.2 - - [08/Aug/2020:19:10:37 +0000] "POST /import/ HTTP/1.0" 500 934094 "http://192.168.1.15/import/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0"

Traceback:

Environment:


Request Method: POST
Request URL: http://192.168.1.15/import/

Django Version: 3.0.7
Python Version: 3.8.4
Installed Applications:
['dal',
 'dal_select2',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django_tables2',
 'django_filters',
 'crispy_forms',
 'emoji_picker',
 'rest_framework',
 'rest_framework.authtoken',
 'django_cleanup.apps.CleanupConfig',
 'cookbook.apps.CookbookConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 '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.locale.LocaleMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']



Traceback (most recent call last):
  File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/opt/recipes/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/opt/recipes/venv/lib/python3.8/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/opt/recipes/cookbook/views/import_export.py", line 31, in import_recipe
    recipe = sr.save()
  File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 230, in save
    return super(BaseNestedModelSerializer, self).save(**kwargs)
  File "/opt/recipes/venv/lib/python3.8/site-packages/rest_framework/serializers.py", line 212, in save
    self.instance = self.create(validated_data)
  File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 258, in create
    self.update_or_create_reverse_relations(instance, reverse_relations)
  File "/opt/recipes/venv/lib/python3.8/site-packages/drf_writable_nested/mixins.py", line 196, in update_or_create_reverse_relations
    raise ValidationError({field_name: errors})

Exception Type: ValidationError at /import/
Exception Value: {'steps': [{'ingredients': [{}, {}, {'food': {'name': [ErrorDetail(string='This field must be unique.', code='unique')]}}, {}, {}, {}, {}, {}, {}, {'unit': {'name': [ErrorDetail(string='This field must be unique.', code='unique')]}}]}]}

An example JSON recipe

.env

# only set this to true when testing/debugging
# when unset: 1 (true) - dont unset this, just for development
DEBUG=1

# hosts the application can run under e.g. recipes.mydomain.com,cooking.mydomain.com,...
ALLOWED_HOSTS=***

# random secret key, use for example base64 /dev/urandom | head -c50 to generate one
SECRET_KEY=***

# add only a database password if you want to run with the default postgres, otherwise change settings accordingly
DB_ENGINE=django.db.backends.postgresql_psycopg2
POSTGRES_HOST=db_recipes
POSTGRES_PORT=5432
POSTGRES_USER=djangodb
POSTGRES_PASSWORD=***
POSTGRES_DB=djangodb

# Serve mediafiles directly using gunicorn. Basically everyone recommends not doing this. Please use any of the examples
# provided that include an additional nxginx container to handle media file serving.
# If you know what you are doing turn this back on (1) to serve media files using djangos serve() method.
# when unset: 1 (true) - this is temporary until an appropriate amount of time has passed for everyone to migrate
GUNICORN_MEDIA=0


# allow authentication via reverse proxy (e.g. authelia), leave of if you dont know what you are doing
# docs: https://github.com/vabene1111/recipes/tree/develop/docs/docker/nginx-proxy%20with%20proxy%20authentication
# when unset: 0 (false)
REVERSE_PROXY_AUTH=0


# the default value for the user preference 'comments' (enable/disable commenting system)
# when unset: 1 (true)
COMMENT_PREF_DEFAULT=1

docker-compose.yml

version: "3"
services:
  db_recipes:
    restart: always
    image: postgres:11-alpine
    volumes:
      - ./postgresql:/var/lib/postgresql/data
    env_file:
      - ./.env

  web_recipes:
    image: vabene1111/recipes
    restart: always
    env_file:
      - ./.env
    volumes:
      - ./staticfiles:/opt/recipes/staticfiles
      - ./mediafiles:/opt/recipes/mediafiles
    depends_on:
      - db_recipes

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 80:80
    env_file:
      - ./.env
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./staticfiles:/static
      - ./mediafiles:/media
@vabene1111 vabene1111 added the bug Something isn't working label Aug 8, 2020
@vabene1111
Copy link
Collaborator

this should be fixed with 782d276

for some reason the id's got into the exports, fix will be released ASP, if you dont want to wait for it you can switch to the develop image but it should not be long (i hope) so better stay on latest

@vabene1111
Copy link
Collaborator

update is released

@RustyRin
Copy link
Author

RustyRin commented Aug 9, 2020

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants