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

Tandoor throws error when deleting image #3501

Open
TheUnlimited64 opened this issue Jan 20, 2025 · 0 comments
Open

Tandoor throws error when deleting image #3501

TheUnlimited64 opened this issue Jan 20, 2025 · 0 comments

Comments

@TheUnlimited64
Copy link

Tandoor Version

1.5.29

Setup

Docker / Docker-Compose

Reverse Proxy

Nginx Proxy Manager (NPM)

Other

Cloudflare

Bug description

I'm having troubles when using tandoor on my selfhosted system using docker.

I'm running through cloudflare and my own nginx proxy. Cloudflare does proxy it (hide my home ip) and then nginx receives the request and passes it to the right port.

My first problem is, that when I import the following recipe: https://www.chefkoch.de/rezepte/1176651223873942/2-Minuten-Pizzaiola.html it does not save any picture. But in the import dialog it detected 4 images and even when I click one, it does not save any image, only a short error message, that dissappears instantly.

The second one is, that if I upload manually an Image and then want to delete it, it throws an exception. The request that it made:

curl 'https://tandoor.mydomain.de/api/recipe/1/image/' \
  -X 'PUT' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'accept-language: de,de-DE;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary6rgs98OnsY9BlCSA' \
  -H 'cookie: csrftoken=<some token>; sessionid=<some sessionid>' \
  -H 'origin: https://tandoor.mydomain.de' \
  -H 'priority: u=1, i' \
  -H 'referer: https://tandoor.mydomain.de/edit/recipe/internal/1/' \
  -H 'sec-ch-ua: "Not A(Brand";v="8", "Chromium";v="132", "Microsoft Edge";v="132"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'sec-fetch-dest: empty' \
  -H 'sec-fetch-mode: cors' \
  -H 'sec-fetch-site: same-origin' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0' \
  -H 'x-csrftoken: <some token>' \
  --data-raw $'------WebKitFormBoundary6rgs98OnsY9BlCSA--\r\n'

My nginx config looks like, I've generated it with perplexity.ai, because my normal one also did not work.

server {
    server_name tandoor.mydomain.de;

    location / {
        proxy_pass http://127.0.0.1:8900;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /media/ {
        proxy_pass http://127.0.0.1:8900;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /static/ {
        proxy_pass http://127.0.0.1:8900;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/home.mydomain.de/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/home.mydomain.de/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

server {
    server_name tandoor.mydomain.de;
    listen 80;
    return 301 https://$server_name$request_uri;
}

My docker-compose:

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

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

  nginx_recipes:
    image: nginx:mainline-alpine
    restart: always
    ports:
      - 8900:80
    env_file:
      - ./.env
    depends_on:
      - web_recipes
    volumes:
      - nginx_config:/etc/nginx/conf.d:ro
      - staticfiles:/static:ro
      - ./mediafiles:/media:ro

volumes:
  nginx_config:
  staticfiles:

Did I misconfigured tandoor, or did I discover a bug?

Relevant logs

::ffff:192.168.16.4 - - [20/Jan/2025:14:39:06 +0100] "PUT /api/recipe/1/image/ HTTP/1.0" 200 86 "https://tandoor.mydomain.de/edit/recipe/internal/1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"

Internal Server Error: /api/recipe/1/image/

Traceback (most recent call last):

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner

    response = get_response(request)

               ^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response

    response = wrapped_callback(request, *callback_args, **callback_kwargs)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view

    return view_func(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/viewsets.py", line 124, in view

    return self.dispatch(request, *args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 509, in dispatch

    response = self.handle_exception(exc)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 469, in handle_exception

    self.raise_uncaught_exception(exc)

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception

    raise exc

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 506, in dispatch

    response = handler(request, *args, **kwargs)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/cookbook/views/api.py", line 1031, in image

    serializer.save()

  File "/opt/recipes/venv/lib/python3.12/site-packages/drf_writable_nested/mixins.py", line 233, in save

    return super(BaseNestedModelSerializer, self).save(**kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 203, in save

    self.instance = self.update(self.instance, validated_data)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/cookbook/serializer.py", line 973, in update

    if not is_file_type_allowed(validated_data['image'].name, image_only=True):

                                ~~~~~~~~~~~~~~^^^^^^^^^

KeyError: 'image'

::ffff:192.168.16.4 - - [20/Jan/2025:14:39:10 +0100] "PUT /api/recipe/1/image/ HTTP/1.0" 500 111604 "https://tandoor.mydomain.de/edit/recipe/internal/1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"

::ffff:192.168.16.4 - - [20/Jan/2025:14:39:14 +0100] "PUT /api/recipe/1/ HTTP/1.0" 200 6512 "https://tandoor.mydomain.de/edit/recipe/internal/1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"

Internal Server Error: /api/recipe/1/image/

Traceback (most recent call last):

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner

    response = get_response(request)

               ^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response

    response = wrapped_callback(request, *callback_args, **callback_kwargs)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/django/views/decorators/csrf.py", line 56, in wrapper_view

    return view_func(*args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/viewsets.py", line 124, in view

    return self.dispatch(request, *args, **kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 509, in dispatch

    response = self.handle_exception(exc)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 469, in handle_exception

    self.raise_uncaught_exception(exc)

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception

    raise exc

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/views.py", line 506, in dispatch

    response = handler(request, *args, **kwargs)

               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/cookbook/views/api.py", line 1031, in image

    serializer.save()

  File "/opt/recipes/venv/lib/python3.12/site-packages/drf_writable_nested/mixins.py", line 233, in save

    return super(BaseNestedModelSerializer, self).save(**kwargs)

           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/venv/lib/python3.12/site-packages/rest_framework/serializers.py", line 203, in save

    self.instance = self.update(self.instance, validated_data)

                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/opt/recipes/cookbook/serializer.py", line 973, in update

    if not is_file_type_allowed(validated_data['image'].name, image_only=True):

                                ~~~~~~~~~~~~~~^^^^^^^^^

KeyError: 'image'

::ffff:192.168.16.4 - - [20/Jan/2025:14:39:19 +0100] "PUT /api/recipe/1/image/ HTTP/1.0" 500 111604 "https://tandoor.mydomain.de/edit/recipe/internal/1/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant