awesto / cookiecutter-django-shop

Cookiecutter django-SHOP is a blueprint for an e-commerce site based on django-CMS.
127 stars 55 forks source link

Items are not added to the cart in Nginx install #28

Closed bartpijn closed 4 years ago

bartpijn commented 4 years ago

Hi,

I have installed the nginx deployment via this cookiecutter template. After setting up the Nginx and lets encrypt containers, the website is available via the domain. I still use the testdata.

What happened?

After trying to place an order, nothing has been added to the cart due to an internal server error in the API, seen below:

webapp_1         | Traceback (most recent call last):
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
webapp_1         |     response = get_response(request)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
webapp_1         |     response = self.process_exception_by_middleware(e, request)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
webapp_1         |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
webapp_1         |     return view_func(*args, **kwargs)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/viewsets.py", line 114, in view
webapp_1         |     return self.dispatch(request, *args, **kwargs)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 505, in dispatch
webapp_1         |     response = self.handle_exception(exc)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 465, in handle_exception
webapp_1         |     self.raise_uncaught_exception(exc)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 476, in raise_uncaught_exception
webapp_1         |     raise exc
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/views.py", line 502, in dispatch
webapp_1         |     response = handler(request, *args, **kwargs)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/shop/views/cart.py", line 39, in create
webapp_1         |     item_serializer.is_valid(raise_exception=True)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 235, in is_valid
webapp_1         |     self._validated_data = self.run_validation(self.initial_data)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 430, in run_validation
webapp_1         |     value = self.to_internal_value(data)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 483, in to_internal_value
webapp_1         |     for field in fields:
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 366, in _writable_fields
webapp_1         |     for field in self.fields.values():
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/django/utils/functional.py", line 80, in __get__
webapp_1         |     res = instance.__dict__[self.name] = self.func(instance)
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 360, in fields
webapp_1         |     for key, value in self.get_fields().items():
webapp_1         |   File "/usr/local/lib/python3.6/site-packages/rest_framework/serializers.py", line 1056, in get_fields
webapp_1         |     fields[field_name] = field_class(**field_kwargs)
webapp_1         | TypeError: __init__() got an unexpected keyword argument 'encoder'
webapp_1         | [pid: 1|app: 0|req: 29/42] 213.127.30.251 () {54 vars in 1145 bytes} [Wed Apr  1 17:50:32 2020] POST /shop/api/cart/ => generated 27 bytes in 25 msecs (HTTP/2.0 500) 4 headers in 136 bytes (1 switches on core 0)

What should've happened instead?

Item should have been added to the cart. In other installations (runserver for example) this did work.

Steps to reproduce

1) install via cookiecutter template (Nginx) 2) open catalog 3) open any item and add it to the cart

bartpijn commented 4 years ago

I found the problem, JSONField in django.contrib.postgres.fields uses an extra argument 'encoder' which is not expected by the serializer.