Related
Overriding save method with super returns unique contraint error when creating object. How to solve it?
Adding context to the code. I need to create an object1 and I need to assign some value dependent on a related foreign object. I need to assign the value after creating an instance of object1, otherwise an error pops up that the object does not exist and there is no relationship.
def save(self, *args, **kwargs):
if self.pk is None:
super(IntoDocumentProduct, self).save(*args, **kwargs)
# some logic
# more logic
super(IntoDocumentProduct, self).save(*args, **kwargs)
self.full_clean()
I am also posting the error that shows up when I test the api in insomnia.
IntegrityError at /api/wms/intodocuments/products/create/
duplicate key value violates unique constraint "wms_dokumentprzyjeciaprodukt_pkey"
DETAIL: Key (id)=(151) already exists.
Below is the error that appears in the console. It directs specifically to the save() method in the model. I don't know what is wrong with it. After all, I can't use self.save(), because there will be a recursive loop.
Traceback (most recent call last):
File "W:\projects\foodgast\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\views\generic\base.py", line 103, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Sebastian\AppData\Local\Programs\Python\Python311\Lib\contextlib.py", line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\src\wms\api\views.py", line 183, in post
serializer.save()
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\serializers.py", line 212, in save
self.instance = self.create(validated_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\rest_framework\serializers.py", line 962, in create
instance = ModelClass._default_manager.create(**validated_data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\query.py", line 671, in create
obj.save(force_insert=True, using=self.db)
File "W:\projects\foodgast\src\wms\models.py", line 621, in save
super(IntoDocumentProduct, self).save(*args, **kwargs)
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\base.py", line 812, in save
self.save_base(
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\base.py", line 863, in save_base
updated = self._save_table(
^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\base.py", line 1006, in _save_table
results = self._do_insert(
^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\base.py", line 1047, in _do_insert
return manager._insert(
^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\query.py", line 1791, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\models\sql\compiler.py", line 1660, in execute_sql
cursor.execute(sql, params)
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\backends\utils.py", line 103, in execute
return super().execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\backends\utils.py", line 67, in execute
return self._execute_with_wrappers(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\backends\utils.py", line 80, in _execute_with_wrappers
return executor(sql, params, many, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\backends\utils.py", line 84, in _execute
with self.db.wrap_database_errors:
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\utils.py", line 91, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "W:\projects\foodgast\venv\Lib\site-packages\django\db\backends\utils.py", line 89, in _execute
return self.cursor.execute(sql, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.IntegrityError: duplicate key value violates unique constraint "wms_dokumentprzyjeciaprodukt_pkey"
DETAIL: Key (id)=(150) already exists.
I'm like 90% sure you have to define your super properly. I tried what you have and didn't get a compile error, but it's definitely not best practices. Particularly, if you're not defining a return within your if statement. That would cause super to be called twice which could be throwing the exception due to the save function running twice. I typically set it right after my function declaration (my prefered method) or as my last line.
def save(self, *args, **kwargs):
super(IntoDocumentProduct, self).save(*args, **kwargs)
# your overwrite code
or
def save(self, *args, **kwargs):
# your overwrite code
super(IntoDocumentProduct, self).save(*args, **kwargs)
So I want to asynchronously conduct file saves to django file storage. I've tried to achieve this by overwriting the default File System Storage class.
import hashlib
import os
import uuid
import django.core.files.storage as storage
from celery import shared_task
from django.core.files import File
class DefaultStorage(storage.FileSystemStorage):
def __init__(self):
super(DefaultStorage, self).__init__()
#shared_task
def _save(self, name, content):
# need to encrypt file before saving
return super(DefaultStorage, self)._save(name, content)
#shared_task
def _open(self, name, mode='rb'):
# need to decrypt before opening
return File(open(self.path(name), mode))
def get_available_name(self, name, max_length=None):
# we return a hash of the file given,
# in case we miss out on uniqueness, django calls
# the get_alternative_name method
dir_name, file_name = os.path.split(name)
file_root, file_ext = os.path.splitext(file_name)
file_root = hashlib.md5(file_root.encode()).hexdigest()
name = os.path.join(dir_name, file_root + file_ext)
return super(DefaultStorage, self).get_available_name(name, max_length)
def get_alternative_name(self, file_root, file_ext):
# we insert a random uuid hex string into the given
# file name before returning the same back
return '%s%s%s' % (file_root, uuid.uuid4().hex, file_ext)
def save(self, name, content, max_length=None):
# override existing system storage save method
# to ensure that we call the shared task and
# utilize the distributed task queue celery offers
has_chunks = hasattr(content, 'chunks')
name = content.name if not name else name
content = File(content, name) if not has_chunks else content
name = self.get_available_name(name, max_length=max_length)
saved = self._save.delay(self, name, content)
return saved
def open(self, name, mode='rb'):
# override existing system storage open method
# to ensure that we call the shared task and
# utilize the distributed task queue celery offers
return self._open.delay(name, mode)
The idea is to override the existing save method to fire off the shared_task named _save. However, I am facing the following error while trying to do the same.
Traceback (most recent call last):
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\generics.py", line 242, in post
return self.create(request, *args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\mixins.py", line 19, in create
self.perform_create(serializer)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\mixins.py", line 24, in perform_create
serializer.save()
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\serializers.py", line 205, in save
self.instance = self.create(validated_data)
File "C:\Users\iyapp\PycharmProjects\cloud-server\api_backend\serializers\partial.py", line 32, in create
return super(PartialUploadSerializer, self).create(validated_data)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\rest_framework\serializers.py", line 939, in create
instance = ModelClass._default_manager.create(**validated_data)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\query.py", line 447, in create
obj.save(force_insert=True, using=self.db)
File "C:\Users\iyapp\PycharmProjects\cloud-server\api_backend\models\uploads.py", line 30, in save
super(Upload, self).save(*args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\base.py", line 754, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\base.py", line 792, in save_base
force_update, using, update_fields,
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\base.py", line 895, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\base.py", line 935, in _do_insert
using=using, raw=raw,
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\query.py", line 1254, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1396, in execute_sql
for sql, params in self.as_sql():
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1341, in as_sql
for obj in self.query.objs
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1341, in <listcomp>
for obj in self.query.objs
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1340, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1291, in pre_save_val
return field.pre_save(obj, add=True)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\fields\files.py", line 307, in pre_save
file.save(file.name, file.file, save=False)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\django\db\models\fields\files.py", line 87, in save
self.name = self.storage.save(name, content, max_length=self.field.max_length)
File "C:\Users\iyapp\PycharmProjects\cloud-server\api_backend\models\storage\default_storage.py", line 48, in save
saved = self._save.delay(self, name, content)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\celery\app\task.py", line 421, in delay
return self.apply_async(args, kwargs)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\celery\app\task.py", line 565, in apply_async
**options
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\celery\app\base.py", line 749, in send_task
amqp.send_task_message(P, name, message, **options)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\celery\app\amqp.py", line 532, in send_task_message
**properties
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\messaging.py", line 166, in publish
compression, headers)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\messaging.py", line 249, in _prepare
body) = dumps(body, serializer=serializer)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\serialization.py", line 220, in dumps
payload = encoder(data)
File "C:\Users\iyapp\AppData\Local\Programs\Python\Python36-32\lib\contextlib.py", line 99, in __exit__
self.gen.throw(type, value, traceback)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\serialization.py", line 53, in _reraise_errors
reraise(wrapper, wrapper(exc), sys.exc_info()[2])
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\exceptions.py", line 21, in reraise
raise value.with_traceback(tb)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\serialization.py", line 49, in _reraise_errors
yield
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\serialization.py", line 220, in dumps
payload = encoder(data)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\utils\json.py", line 66, in dumps
**dict(default_kwargs, **kwargs))
File "C:\Users\iyapp\AppData\Local\Programs\Python\Python36-32\lib\json\__init__.py", line 238, in dumps
**kw).encode(obj)
File "C:\Users\iyapp\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\iyapp\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\iyapp\PycharmProjects\cloud-server\venv\lib\site-packages\kombu\utils\json.py", line 55, in default
return super().default(o)
File "C:\Users\iyapp\AppData\Local\Programs\Python\Python36-32\lib\json\encoder.py", line 180, in default
o.__class__.__name__)
kombu.exceptions.EncodeError: Object of type 'DefaultStorage' is not JSON serializable
I believe I have found the source of the issue. It is because we cannot pass "file" objects as parameters to shared_task functions. If this is the case, then how can I send my file to the _save function?
Before sending, the file isn't saved yet. We need to save the file only after receiving.
I am using the HelloWorld example located at the ViewFlow cookbook.
The whole source code is same as the helloworld project with the only change being:
flows.py
check_approve = (
flow.If(lambda activation: activation.process.approved)
.Then(this.send)
.Else(this.start) # Edited (was this.end)
)
So basically I intend that if user keeps the Approved checkbox as un-selected and proceeds then it will push the task back to the start step.
I get this error when I run it:
NotImplementedError at /workflow/helloworld/helloworld/3/approve/11/
No exception message supplied
Internal Server Error: /workflow/helloworld/helloworld/3/approve/11/
Traceback (most recent call last):
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 67, in _wrapper
return bound_func(*args, **kwargs)
File "/usr/lib/python3.6/contextlib.py", line 52, in inner
return func(*args, **kwds)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/decorators.py", line 213, in _wrapper
return view(request, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/utils/decorators.py", line 63, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 70, in dispatch
return super(BaseFlowMixin, self).dispatch(request, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/base.py", line 88, in dispatch
return handler(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/edit.py", line 240, in post
return super(BaseUpdateView, self).post(request, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/django/views/generic/edit.py", line 183, in post
return self.form_valid(form)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 86, in form_valid
self.activation_done(*args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/flow/views/task.py", line 78, in activation_done
self.activation.done()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 384, in done
self.activate_next()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 396, in activate_next
self.flow_task._next.activate(prev_activation=self, token=self.task.token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/__init__.py", line 154, in activate
return self.activation_class.activate(self, prev_activation, token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 561, in activate
activation.perform()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 112, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 525, in perform
self.activate_next()
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 44, in __call__
return self.descriptor(self.instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/fsm.py", line 169, in __call__
result = self.func(instance, *args, **kwargs)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/nodes/ifgate.py", line 24, in activate_next
self.flow_task._on_false.activate(prev_activation=self, token=self.task.token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/__init__.py", line 154, in activate
return self.activation_class.activate(self, prev_activation, token)
File "/home/admin-12/PycharmProjects/viewflow1/venv/lib/python3.6/site-packages/viewflow/activation.py", line 216, in activate
raise NotImplementedError
NotImplementedError
The problem seem to be that you try to jump to a flow.Start element in the else statement. Please try to jump to e.g. a flow.View element instead.
We are getting traceback errors whenever we select products or contact, our website apps runs Ok but we can't install e-commerce module which we remove recently what is causing it ? Please help
Odoo Server Error
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 648, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 321, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 314, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 964, in __call__
return self.method(*args, **kw)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 514, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python2.7/site-packages/openerp/addons/web/controllers/main.py", line 828, in search_read
return self.do_search_read(model, fields, offset, limit, domain, sort)
File "/usr/lib/python2.7/site-packages/openerp/addons/web/controllers/main.py", line 849, in do_search_read
request.context)
File "/usr/lib/python2.7/site-packages/openerp/http.py", line 1069, in proxy
result = meth(cr, request.uid, *args, **kw)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 5297, in search_read
result = self.read(cr, uid, record_ids, fields, context=read_ctx)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 250, in wrapper
return old_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3203, in read
result = BaseModel.read(records, fields, load=load)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3238, in read
self._read_from_database(stored, inherited)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3429, in _read_from_database
res2 = self._columns[f].get(cr, self._model, ids, f, user, context=context, values=result)
File "/usr/lib/python2.7/site-packages/openerp/osv/fields.py", line 1501, in get
result = self._fnct(obj, cr, uid, ids, name, self._arg, context)
File "/usr/lib/python2.7/site-packages/openerp/addons/product/product.py", line 435, in _product_currency
res[product.id] = product.company_id.currency_id.id or main_company.currency_id.id
File "/usr/lib/python2.7/site-packages/openerp/fields.py", line 830, in __get__
self.determine_value(record)
File "/usr/lib/python2.7/site-packages/openerp/fields.py", line 930, in determine_value
record._prefetch_field(self)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3308, in _prefetch_field
result = records.read([f.name for f in fs], load='_classic_write')
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3238, in read
self._read_from_database(stored, inherited)
File "/usr/lib/python2.7/site-packages/openerp/api.py", line 248, in wrapper
return new_api(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/models.py", line 3376, in _read_from_database
cr.execute(query_str, params)
File "/usr/lib/python2.7/site-packages/openerp/sql_db.py", line 141, in wrapper
return f(self, *args, **kwargs)
File "/usr/lib/python2.7/site-packages/openerp/sql_db.py", line 220, in execute
res = self._obj.execute(query, params)
ProgrammingError: column product_template.website_description does not exist
LINE 1: ...e" as "state","product_template"."type" as
"type","product_t...
^
I have a django app which is running on 1.6 with python 3. Recently I have added django-storages to my app.
When I am trying to save a model(record) which worked well previously, its showing up the below error
Traceback (most recent call last):
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/handlers/base.py", line 112, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 432, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/views/decorators/cache.py", line 52, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 198, in inner
return view(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 29, in _wrapper
return bound_func(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 99, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/utils/decorators.py", line 25, in bound_func
return func(self, *args2, **kwargs2)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/transaction.py", line 371, in inner
return func(*args, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 1131, in add_view
self.save_model(request, new_object, form, False)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/admin/options.py", line 860, in save_model
obj.save()
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 545, in save
force_update=force_update, update_fields=update_fields)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 573, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 654, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/base.py", line 687, in _do_insert
using=using, raw=raw)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/manager.py", line 232, in _insert
return insert_query(self.model, objs, fields, **kwargs)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/query.py", line 1514, in insert_query
return query.get_compiler(using=using).execute_sql(return_id)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 902, in execute_sql
for sql, params in self.as_sql():
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in as_sql
for obj in self.query.objs
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 860, in <listcomp>
for obj in self.query.objs
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 858, in <listcomp>
for f in fields
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 252, in pre_save
file.save(file.name, file, save=False)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 87, in save
setattr(self.instance, self.field.name, self.name)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 311, in __set__
self.field.update_dimension_fields(instance, force=True)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 381, in update_dimension_fields
width = file.width
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 17, in _get_width
return self._get_image_dimensions()[0]
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/images.py", line 27, in _get_image_dimensions
self.open()
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/db/models/fields/files.py", line 76, in open
self.file.open(mode)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 121, in open
if not self.closed:
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/base.py", line 59, in _get_closed
return not self.file or self.file.closed
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 406, in _get_file
self.key.get_contents_to_file(self._file)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1643, in get_contents_to_file
response_headers=response_headers)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1475, in get_file
query_args=None)
File "/Users/david/.virtualenvs/project/lib/python3.4/site-packages/boto/s3/key.py", line 1529, in _get_file_internal
fp.write(bytes)
TypeError: string argument expected, got 'bytes'
model
class RequisitionImage(models.Model, ImageRisizeToolbox):
image_id = models.AutoField(primary_key=True)
requisition = models.ForeignKey(Requisition)
description = models.CharField(max_length=80)
image_file = models.ImageField(upload_to=get_file_path, height_field='image_height', width_field='image_width')
thumbnail_file = models.ImageField(upload_to=get_file_path, blank=True, null=True)
sort_order = models.SmallIntegerField(blank=True, null=True)
filetype = models.CharField(max_length=10, blank=True, null=True)
objects = models.Manager()
cust_objects = RequisitionImageManager()
MAX_SIZE = 4000000 # Image file size limit
def __str__(self):
return self.description
I am getting this error when i am trying to save the RequisitionImage object record both from the admin model and from my view.
So how to avoid this error and what is causing it ?