Cannot force an update in save() with no primary key - python

I am working with a custom build user model in Django and there was some message in the terminal at the time of migrate given in the stackoverflow link.
However, I have failed to solve that and it didn't hamper to run the project, so I actually ignore it and continue with my code. Now when I try to log-in to the admin panel(http://127.0.0.1:8000/admin/) it shows the following error:
Internal Server Error: /admin/login/
Traceback (most recent call last):
File "G:\Python\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
File "G:\Python\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "G:\Python\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "G:\Python\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\contrib\admin\sites.py", line 407, in login
return LoginView.as_view(**defaults)(request)
File "G:\Python\lib\site-packages\django\views\generic\base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "G:\Python\lib\site-packages\django\views\decorators\debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "G:\Python\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "G:\Python\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\contrib\auth\views.py", line 63, in dispatch
return super().dispatch(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\views\generic\base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "G:\Python\lib\site-packages\django\views\generic\edit.py", line 142, in post
return self.form_valid(form)
File "G:\Python\lib\site-packages\django\contrib\auth\views.py", line 92, in form_valid
auth_login(self.request, form.get_user())
File "G:\Python\lib\site-packages\django\contrib\auth\__init__.py", line 131, in login
user_logged_in.send(sender=user.__class__, request=request, user=user)
File "G:\Python\lib\site-packages\django\dispatch\dispatcher.py", line 173, in send
return [
File "G:\Python\lib\site-packages\django\dispatch\dispatcher.py", line 174, in <listcomp>
(receiver, receiver(signal=self, sender=sender, **named))
File "G:\Python\lib\site-packages\django\contrib\auth\models.py", line 20, in update_last_login
user.save(update_fields=['last_login'])
File "G:\Python\lib\site-packages\django\contrib\auth\base_user.py", line 66, in save
super().save(*args, **kwargs)
File "G:\Python\lib\site-packages\django\db\models\base.py", line 745, in save
self.save_base(using=using, force_insert=force_insert,
File "G:\Python\lib\site-packages\django\db\models\base.py", line 782, in save_base
updated = self._save_table(
File "G:\Python\lib\site-packages\django\db\models\base.py", line 847, in _save_table
raise ValueError("Cannot force an update in save() with no primary key.")
ValueError: Cannot force an update in save() with no primary key.

I was facing the same issue,I searched everywhere.
I found the answer in the link I will attach below.
1-to change the database name.
2-makemigrations and migrate.
but it failed to work until I read towen's comment! I was always creating
the super user before
migrating, which is wrong!
you have make the migrations before creating the super user.
so
python manage.py makemigrations
then
python manage.py migrate
then all the tables are ready to work properly, now we can create the super user, and it will have the primary key and it will work
python manage.py createsuperuser
https://github.com/nesdis/djongo/issues/3

Related

Unsupported operation error creating and saving json file

Ive been trying to save a json file created from a to a filefield, I got an unsuported operation error "not readable", this is my code
from django.core.files.base import File
#receiver(post_save,sender=ProyArq)
def ifc_a_json(sender,instance,*args,**kwargs):
if instance.arch_ifc:
jsoon = ifc_2_json("path_to_file")
json_file_nom = instance.nombre.replace(' ','')+'.json'
with open(json_file_nom, 'w') as outfile:
json.dump(jsoon, outfile, indent=2)
json_fk = JsonIFC.objects.create(proy_fk=instance)
json_fk.ifc_json.save(json_file_nom,File(outfile),True)
im working with IFC files, and I want to store them also as json, I tried instead of saving the json as a JSONField, to save it as a foreign key file since the size of the json Im working are above 10mb, is this the best approach for this??
error details
Exception Type: UnsupportedOperation
Exception Value: not readable
Exception Location: /home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/files/base.py in chunks, line 60
Traceback (most recent call last):
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1641, in change_view
return self.changeform_view(request, object_id, form_url, extra_context)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1565, in _changeform_view
self.save_model(request, new_object, form, not add)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/contrib/admin/options.py", line 1081, in save_model
obj.save()
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/db/models/base.py", line 746, in save
force_update=force_update, update_fields=update_fields)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/db/models/base.py", line 795, in save_base
update_fields=update_fields, raw=raw, using=using,
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in send
for receiver in self._live_receivers(sender)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/dispatch/dispatcher.py", line 175, in <listcomp>
for receiver in self._live_receivers(sender)
File "/home/fcr/anaconda3/envs/gda/a_viurb/b_proy/models.py", line 105, in ifc_a_json
json_fk.ifc_json.save(json_file_nom,File(outfile),True)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/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 "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/files/storage.py", line 52, in save
return self._save(name, content)
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/files/storage.py", line 271, in _save
for chunk in content.chunks():
File "/home/fcr/anaconda3/envs/gda/lib/python3.7/site-packages/django/core/files/base.py", line 60, in chunks
data = self.read(chunk_size)
io.UnsupportedOperation: not readable
I solved the error, I needed to change the file open from "w" to "a+", which allows reading and writing

can not save pages any more in wagtail

when clicking publish or save draft I got this error
wagtail.core.models.Page.DoesNotExist: Page matching query does not exist.
this happens only with old pages, the newly created pages are being able to be created and saved without any errors
NB: the new pages do not have children pages yet
trying to find out what is causing this error despite I did not override the save method
any suggestion or hint will be very helpful thank you
here the traceback:
wagtail.core.models.DoesNotExist
wagtail.core.models.Page.DoesNotExist: Page matching query does not exist.
Traceback (most recent call last)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/base.py", line 130, in get_response
response = self._middleware_chain(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 103, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 138, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django_extensions/management/technical_response.py", line 37, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/urls/__init__.py", line 127, in wrapper
return view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/auth.py", line 172, in decorated_view
response = view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 131, in dispatch
return super().dispatch(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 218, in post
return self.form_valid(self.form)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 238, in form_valid
return self.publish_action()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 286, in publish_action
revision.publish(
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 2972, in publish
page.save()
File "/home/oladhari/gounite-v2/GOunite/v2/home/models.py", line 98, in save
super().save(*args, **kwargs)
File "/usr/lib/python3.8/contextlib.py", line 75, in inner
return func(*args, **kwds)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 1028, in save
result = super().save(**kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/modelcluster/models.py", line 199, in save
getattr(self, relation).commit()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/modelcluster/fields.py", line 202, in commit
item.delete()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 1094, in delete
return Page.objects.get(id=self.id).delete(*args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/db/models/query.py", line 429, in get
raise self.model.DoesNotExist(
wagtail.core.models.Page.DoesNotExist: Page matching query does not exist.
The part that is throwing errors looks like code in your models that relates one page to other pages. See this line: return Page.objects.get(id=self.id).delete(*args, **kwargs)? So I think we need to know what "items" are and how the page you are saving uses them.
Please post the models for the page you are saving and the pages that are referenced as 'items'
Finally resolved it
we should not use ParentalKey with a Page model (we were using it in GOPart model which is a Page model, changing it to ForeignKey resolved the error and now we can save the HomePage
class MyModel(RoutablePageMixin, Page, Orderable):
parent_page_types: list = []
company = ParentalKey(
"home.HomePage",
on_delete=models.SET_NULL,
verbose_name=_("Company"),
null=True,
blank=False,
)
changing it to:
class MyModel(RoutablePageMixin, Page):
parent_page_types: list = []
company = models.ForeignKey(
"home.HomePage",
on_delete=models.SET_NULL,
verbose_name=_("Company"),
null=True,
blank=False,
)
a Page can not be Orderable

DatabaseError: value too long for type character varying(20)

Solution:- I had deleted my migration .py files which caused this problem. Creating a new app with the same code works now.
I am not sure why i get a varying(20) error even when the max_length I've set is 200 for a CharField
I looked at all the other posts and all of them had an issue with the length of the value.
However, even if i enter "abc" in the name field it gives me this error. Any help is appreciated. Thanks!
Django Version: 3.1.5
Python Version: 3.8.5
from django.db import models
from django.contrib.gis.db import models
from django.db.models import Manager as GeoManager
# Create your models here.
class Incidences(models.Model):
name = models.CharField(max_length=200)
location = models.PointField(srid=4326)
objects = GeoManager()
def _str_(self):
return self.name
Traceback (most recent call last):
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
The above exception (value too long for type character varying(20)
) was the direct cause of the following exception:
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\options.py", line 614, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\sites.py", line 233, in inner
return view(request, *args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\options.py", line 1653, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\options.py", line 1534, in changeform_view
return self._changeform_view(request, object_id, form_url, extra_context)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\options.py", line 1580, in _changeform_view
self.save_model(request, new_object, form, not add)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\contrib\admin\options.py", line 1093, in save_model
obj.save()
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\models\base.py", line 753, in save
self.save_base(using=using, force_insert=force_insert,
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\models\base.py", line 790, in save_base
updated = self._save_table(
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\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\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\models\base.py", line 933, in _do_insert
return manager._insert(
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\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\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\models\sql\compiler.py", line 1397, in execute_sql
cursor.execute(sql, params)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 98, in execute
return super().execute(sql, params)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 66, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 75, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\utils.py", line 90, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\anuj\geo_django_tutorial\tutorial_geodjango\lifeingis\lib\site-packages\django\db\backends\utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
Exception Type: DataError at /admin/reporter/incidences/add/
Exception Value: value too long for type character varying(20)

TypeError: __str__ returned non-string (type NoneType) With Django third party package Models

I installed the django_message package into my django app using django 2.0 and while it works on my development machine, it throws the following errors on production when I try to open the list of messages from Django Admin console.
TypeError: __str__ returned non-string (type NoneType)
[22/Mar/2019 15:08:12] ERROR [django.request:118] Internal Server Error: /admin/django_messages/message/
Traceback (most recent call last):
File "/opt/site_env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
response = get_response(request)
File "/opt/site_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/opt/site_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 574, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
return bound_func(*args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/opt/site_env/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
return func.__get__(self, type(self))(*args2, **kwargs2)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1570, in changelist_view
cl = self.get_changelist_instance(request)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 705, in get_changelist_instance
self,
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 76, in __init__
self.queryset = self.get_queryset(request)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 320, in get_queryset
filters_use_distinct) = self.get_filters(request)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 130, in get_filters
self.model, self.model_admin, field_path=field_path
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/filters.py", line 157, in create
return list_filter_class(field, request, params, model, model_admin, field_path=field_path)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/filters.py", line 168, in __init__
self.lookup_choices = self.field_choices(field, request, model_admin)
File "/opt/site_env/lib/python3.6/site-packages/django/contrib/admin/filters.py", line 195, in field_choices
return field.get_choices(include_blank=False)
File "/opt/site_env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 812, in get_choices
limit_choices_to)]
File "/opt/site_env/lib/python3.6/site-packages/django/db/models/fields/__init__.py", line 811, in <listcomp>
for x in rel_model._default_manager.complex_filter(
File "/opt/site_env/lib/python3.6/site-packages/django/utils/encoding.py", line 34, in smart_text
return force_text(s, encoding, strings_only, errors)
File "/opt/site_env/lib/python3.6/site-packages/django/utils/encoding.py", line 67, in force_text
s = str(s)
TypeError: __str__ returned non-string (type NoneType)
The biggest concern is that this is not the only model that is throwing the error. I have the same from django-allauth throwing the same error with SocialAccount.
Another concern is that I don't think I should be fixing the codes from this packages but I am left with nothing else.
Also to note, that none of the models for the application itself causes these error.
Only applies to django_allauth and django_messages. However, the failure doesn't happen in my development machine.
The mysql table for django_messages is empty (without records).
Is there a config that causes these kinds of errors or somethings.
I am using django 2.0 and python 3.6 in both enviroments.
Figured out.
It turns out that all the models failing are related to the User model whose str() method points to a field that has its database column as NULLs.
Solution: I have to make that field not nullable at the database level and at django level by assigning default value at the pre_save phase.
It worked.

KeyError: 'wizard_activation_wizard'

I recently upgraded from Django 1.6.11 to Django 1.8.9, and installed django-formtools==1.0 as part of the process. I am getting this error, which does not point to a single line of my code. Has anyone come across this?
Internal Server Error: /accounts/activation-process/maria-cristo-2/
Traceback (most recent call last):
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/formtools/wizard/views.py", line 237, in dispatch
response = super(WizardView, self).dispatch(request, *args, **kwargs)
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/django/views/generic/base.py", line 89, in dispatch
return handler(request, *args, **kwargs)
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/formtools/wizard/views.py", line 300, in post
return self.render_done(form, **kwargs)
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/formtools/wizard/views.py", line 358, in render_done
self.storage.reset()
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/formtools/wizard/storage/base.py", line 34, in reset
wizard_files = self.data[self.step_files_key]
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/formtools/wizard/storage/session.py", line 13, in _get_data
return self.request.session[self.prefix]
File "/home/vagrant/virtualenvs/staging/local/lib/python2.7/site-packages/django/contrib/sessions/backends/base.py", line 48, in __getitem__
return self._session[key]
KeyError: 'wizard_activation_wizard'

Categories