I am using djangocms_blog.
Today I updated django from 3.1 to 3.2.12 and suddenly when I try to delete post object, there is "Cannot call delete() after .distinct()" error
Traceback:
env\lib\site-packages\django\core\handlers\exception.py, line 47, in inner
response = get_response(request) …
env\lib\site-packages\django\core\handlers\base.py, line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs) …
env\lib\site-packages\django\contrib\admin\options.py, line 616, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs) …
env\lib\site-packages\django\utils\decorators.py, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs) …
env\lib\site-packages\django\views\decorators\cache.py, line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs) …
env\lib\site-packages\django\contrib\admin\sites.py, line 232, in inner
return view(request, *args, **kwargs) …
env\lib\site-packages\django\utils\decorators.py, line 43, in _wrapper
return bound_method(*args, **kwargs) …
env\lib\site-packages\django\utils\decorators.py, line 130, in _wrapped_view
response = view_func(request, *args, **kwargs) …
env\lib\site-packages\django\contrib\admin\options.py, line 1739, in changelist_view
response = self.response_action(request, queryset=cl.get_queryset(request)) …
env\lib\site-packages\django\contrib\admin\options.py, line 1408, in response_action
response = func(self, request, queryset) …
env\lib\site-packages\django\contrib\admin\actions.py, line 45, in delete_selected
modeladmin.delete_queryset(request, queryset) …
env\lib\site-packages\django\contrib\admin\options.py, line 1109, in delete_queryset
queryset.delete() …
env\lib\site-packages\django\db\models\query.py, line 728, in delete
raise TypeError('Cannot call delete() after .distinct().') …
I restored Django 3.1 version and everything works fine, but working on old version isn't best solution
Fixed via setting
Django = ">=3.2,<3.3"
in pyproject.toml, so it selected itself Django 3.2.13.
Related
I'm running:
Python 3.7.3
Django 3.1.14
social-auth-app-django 3.1.0
When I try to upgrade social-auth-app-django to 3.3.0 or 3.4.0, I get:
Traceback (most recent call last):
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_django/utils.py", line 49, in wrapper
return func(request, backend, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_django/views.py", line 33, in complete
*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/actions.py", line 45, in do_complete
user = backend.complete(user=user, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/base.py", line 40, in complete
return self.auth_complete(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/utils.py", line 247, in wrapper
return func(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/oauth.py", line 181, in auth_complete
return self.do_auth(access_token, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/utils.py", line 247, in wrapper
return func(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/oauth.py", line 192, in do_auth
return self.strategy.authenticate(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_django/strategy.py", line 107, in authenticate
return authenticate(*args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/contrib/auth/__init__.py", line 73, in authenticate
user = backend.authenticate(request, **credentials)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/base.py", line 80, in authenticate
return self.pipeline(pipeline, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/base.py", line 83, in pipeline
out = self.run_pipeline(pipeline, pipeline_index, *args, **kwargs)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/backends/base.py", line 113, in run_pipeline
result = func(*args, **out) or {}
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/social_core/pipeline/user.py", line 119, in user_details
setattr(user, name, value)
File "/data/project/spi-tools-dev/www/python/venv/lib/python3.7/site-packages/django/db/models/fields/related_descriptors.py", line 547, in __set__
% self._get_set_deprecation_msg_params(),
Exception Type: TypeError at /oauth/complete/mediawiki/
Exception Value: Direct assignment to the forward side of a many-to-many set is prohibited. Use groups.set() instead.
when I try to authenticate. Any idea what's going on?
The TL;DR is to add
SOCIAL_AUTH_PROTECTED_USER_FIELDS = ['groups']
to settings.py. See here for the longer version.
I am trying to sort column of ModelAdmin list field with admin_order_field with nulls_last such as:
class UserProfileAdmin(admin.ModelAdmin):
def get_sum_amount(self, obj):
return obj.sum_amount
get_sum_amount.admin_order_field = F('sum_amount').desc(nulls_last=True)
But I am getting following error:
Traceback (most recent call last):
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 606, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
return view(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1672, in changelist_view
cl = self.get_changelist_instance(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/options.py", line 744, in get_changelist_instance
sortable_by,
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 81, in __init__
self.queryset = self.get_queryset(request)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/contrib/admin/views/main.py", line 436, in get_queryset
qs = qs.order_by(*ordering)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/db/models/query.py", line 1074, in order_by
obj.query.add_ordering(*field_names)
File "/home/petr/.local/share/virtualenvs/aklub_project-HrPEZ5ak/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1804, in add_ordering
if not hasattr(item, 'resolve_expression') and not ORDER_PATTERN.match(item):
TypeError: expected string or bytes-like object
I am using Django 2.2. Is this issue in Django or am I doing something wrong?
This is now possible in Django starting with version 3.1.
I am using django-rest-auth registration api, I overridden that by using my own SERIALIZER and model. So I am getting error.
I have tried by setting active at the time user created. But that is not working.
Let me know how to resolve this type of problem.
[12/Jan/2019 17:24:06] "POST /rest-auth/registration/ HTTP/1.1" 400 68
Internal Server Error: /rest-auth/registration/
Traceback (most recent call last):
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/core/handlers/base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/utils/decorators.py", line 45, in _wrapper
return bound_method(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/views/decorators/debug.py", line 76, in sensitive_post_parameters_wrapper
return view(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 46, in dispatch
return super(RegisterView, self).dispatch(*args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 495, in dispatch
response = self.handle_exception(exc)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 455, in handle_exception
self.raise_uncaught_exception(exc)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/views.py", line 492, in dispatch
response = handler(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_framework/generics.py", line 192, in post
return self.create(request, *args, **kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 65, in create
user = self.perform_create(serializer)
File "/Users/test/project/vblah/lib/python3.6/site-packages/rest_auth/registration/views.py", line 81, in perform_create
None)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/utils.py", line 183, in complete_signup
signal_kwargs=signal_kwargs)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/utils.py", line 133, in perform_login
return adapter.respond_user_inactive(request, user)
File "/Users/test/project/vblah/lib/python3.6/site-packages/allauth/account/adapter.py", line 454, in respond_user_inactive
reverse('account_inactive'))
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/urls/base.py", line 90, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/Users/test/project/vblah/lib/python3.6/site-packages/django/urls/resolvers.py", line 622, in _reverse_with_prefix
raise NoReverseMatch(msg)
django.urls.exceptions.NoReverseMatch: Reverse for 'account_inactive' not found. 'account_inactive' is not a valid view function or pattern name.```
this exception happend because in your User model
is_active = False .
so set True and migrate
in models.py set is_active = True
and migrate the tables
When i open to click cms-pages , showing error..
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/core/handlers/base.py", line 111, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/contrib/admin/options.py", line 307, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/utils/decorators.py", line 93, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/views/decorators/cache.py", line 79, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/contrib/admin/sites.py", line 197, in inner
return view(request, *args, **kwargs)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/django_cms-2.2-py2.6.egg/cms/admin/pageadmin.py", line 657, in changelist_view
cl.set_items(request)
File "/home2/devnocco/virtual/lib/python2.6/site-packages/django_cms-2.2-py2.6.egg/cms/admin/change_list.py", line 198, in set_items
children[-1].last = False
File "/home2/devnocco/virtual/lib/python2.6/site-packages/Django-1.3.1-py2.6.egg/django/db/models/query.py", line 157, in __getitem__
"Negative indexing is not supported."
AssertionError: Negative indexing is not supported.
This will happen mostly when you are trying some indexing related operation on an empty list. Try this instead:
somelist=[]
last_element = somelist[len(somelist)-1]
It looks like you are coming across this issue in django-cms. It's been fixed now, so you could upgrade to the latest release, or manually apply the patch.
You might have to upgrade django-mptt to 0.5.2 at the same time.
Should 'save_as' work with inlines. I'm rather baffled by the traceback but it doesn't seem to show much involvement of my own code.
The problem seems to be the id's of inlines being set to '' when saving an add form. This is handled quite happily by when you do a normal 'add':
Traceback:
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/contrib/admin/options.py" in wrapper
307. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
79. response = view_func(request, *args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/contrib/admin/sites.py" in inner
197. return view(request, *args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapper
28. return bound_func(*args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/utils/decorators.py" in _wrapped_view
93. response = view_func(request, *args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/utils/decorators.py" in bound_func
24. return func(self, *args2, **kwargs2)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/transaction.py" in inner
217. res = func(*args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/contrib/admin/options.py" in add_view
879. prefix=prefix, queryset=inline.queryset(request))
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/models.py" in __init__
682. queryset=qs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/models.py" in __init__
415. super(BaseModelFormSet, self).__init__(**defaults)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/formsets.py" in __init__
47. self._construct_forms()
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/formsets.py" in _construct_forms
108. self.forms.append(self._construct_form(i))
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
691. form = super(BaseInlineFormSet, self)._construct_form(i, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/forms/models.py" in _construct_form
437. connection=connections[self.get_queryset().db])
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/models/fields/subclassing.py" in inner
53. return func(*args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/models/fields/subclassing.py" in inner
53. return func(*args, **kwargs)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_db_prep_lookup
306. value = self.get_prep_lookup(lookup_type, value)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_lookup
292. return self.get_prep_value(value)
File "/Users/andybaker/.virtualenvs/nmdc_test/lib/python2.7/site-packages/django/db/models/fields/__init__.py" in get_prep_value
479. return int(value)
Exception Type: ValueError at /admin/property_manager/property/add/
Exception Value: invalid literal for int() with base 10: ''
Could be related to this if you're using FileFields? https://code.djangoproject.com/ticket/14760