Opened 5 years ago
Closed 5 years ago
#32436 closed Bug (invalid)
Unable to logout from Django Admin
| Reported by: | jatindergit | Owned by: | nobody | 
|---|---|---|---|
| Component: | contrib.sessions | Version: | 3.1 | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
Hi there,
I have installed Django 3.1 and migrate the database in db.sqlit3. I have created a superuser using Django admin command. I have successfully logged in but when I am trying to logout it throws an error
Environment:
Request Method: GET
Request URL: http://localhost:8022/admin/logout/
Django Version: 3.1.6
Python Version: 3.8.5
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'tinymce',
 'fixture_magic',
 'metatags',
 'courses',
 'app']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback (most recent call last):
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1774, in get_prep_value
    return int(value)
The above exception (invalid literal for int() with base 10: 'h9f082ycd7lew33j6xldceoy1nhu6o3j') was the direct cause of the following exception:
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 251, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 233, in inner
    return view(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/admin/sites.py", line 376, in logout
    return LogoutView.as_view(**defaults)(request)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/utils/decorators.py", line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/auth/views.py", line 118, in dispatch
    auth_logout(request)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/auth/__init__.py", line 146, in logout
    request.session.flush()
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/sessions/backends/base.py", line 335, in flush
    self.delete()
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py", line 103, in delete
    self.model.objects.get(session_key=session_key).delete()
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/base.py", line 947, in delete
    return collector.delete()
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/deletion.py", line 435, in delete
    signals.post_delete.send(
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 177, in send
    return [
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/dispatch/dispatcher.py", line 178, in <listcomp>
    (receiver, receiver(signal=self, sender=sender, **named))
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/metatags/receivers.py", line 10, in delete_attached_meta_tags
    meta_tags = get_object_or_none(
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/metatags/utils.py", line 20, in get_object_or_none
    return queryset.get(*args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/query.py", line 418, in get
    clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/query.py", line 942, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/query.py", line 962, in _filter_or_exclude
    clone._filter_or_exclude_inplace(negate, *args, **kwargs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/query.py", line 969, in _filter_or_exclude_inplace
    self._query.add_q(Q(*args, **kwargs))
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1358, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1377, in _add_q
    child_clause, needed_inner = self.build_filter(
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1319, in build_filter
    condition = self.build_lookup(lookups, col, value)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1165, in build_lookup
    lookup = lookup_class(lhs, rhs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/lookups.py", line 24, in __init__
    self.rhs = self.get_prep_lookup()
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/lookups.py", line 76, in get_prep_lookup
    return self.lhs.output_field.get_prep_value(self.rhs)
  File "/Users/jatinder.singh/Desktop/projects/GURU/python/env/lib/python3.8/site-packages/django/db/models/fields/__init__.py", line 1777, in get_prep_value
    raise e.__class__(
Exception Type: ValueError at /admin/logout/
Exception Value: Field 'object_id' expected a number but got 'h9f082ycd7lew33j6xldceoy1nhu6o3j'.
I have investigate few things and got that 
env/lib/python3.8/site-packages/django/contrib/sessions/backends/db.py # 103 self.model.objects.get(session_key=session_key).delete()
unable to delete session object because its expecting integer but string in being store in django_sesison.session_key
Please look into this.
Thanks!
 
  Note:
 See   TracTickets
 for help on using tickets.
    
It looks like an issue in
metatagsnot Django itself.