iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
718 stars 47 forks source link

Error Opening Admin Login Page - AttributeError: 'LoginPage' object has no attribute 'items' #430

Open natehouk opened 1 year ago

natehouk commented 1 year ago

I am receiving the following error when accessing the admin page:

AttributeError: 'LoginPage' object has no attribute 'items'

It appears the LoginPage is not returning a proper HttpResponse. I am not sure how to troubleshoot this further. Any ideas?

Environment:

Request Method: GET
Request URL: http://localhost:3000/iommi-admin/login/?next=%2Fiommi-admin%2F

Django Version: 4.2.4
Python Version: 3.11.4
Installed Applications:
['whitenoise.runserver_nostatic',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'grappelli',
 'django.contrib.admin',
 'django.forms',
 'crispy_forms',
 'crispy_bootstrap5',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'django_celery_beat',
 'rest_framework',
 'rest_framework.authtoken',
 'corsheaders',
 'drf_spectacular',
 'django_unicorn',
 'iommi',
 'epsilon.users',
 'epsilon.label',
 'debug_toolbar',
 'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'iommi.live_edit.Middleware',
 'iommi.sql_trace.Middleware',
 'iommi.profiling.Middleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 69, in __call__
    panel.generate_stats(request, response)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/panels/headers.py", line 49, in generate_stats
    self.response_headers = dict(sorted(response.items()))
                                        ^^^^^^^^^^^^^^

Exception Type: AttributeError at /iommi-admin/login/
Exception Value: 'LoginPage' object has no attribute 'items'
natehouk commented 1 year ago

Same thing happens if I try to access the change_password page:

Environment:

Request Method: GET
Request URL: http://localhost:3000/iommi-admin/change_password/

Django Version: 4.2.4
Python Version: 3.11.4
Installed Applications:
['whitenoise.runserver_nostatic',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'grappelli',
 'django.contrib.admin',
 'django.forms',
 'crispy_forms',
 'crispy_bootstrap5',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'django_celery_beat',
 'rest_framework',
 'rest_framework.authtoken',
 'corsheaders',
 'drf_spectacular',
 'django_unicorn',
 'iommi',
 'epsilon.users',
 'epsilon.label',
 'debug_toolbar',
 'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'whitenoise.middleware.WhiteNoiseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'iommi.live_edit.Middleware',
 'iommi.sql_trace.Middleware',
 'iommi.profiling.Middleware',
 'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 69, in __call__
    panel.generate_stats(request, response)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/debug_toolbar/panels/headers.py", line 49, in generate_stats
    self.response_headers = dict(sorted(response.items()))
                                        ^^^^^^^^^^^^^^

Exception Type: AttributeError at /iommi-admin/change_password/
Exception Value: 'ChangePasswordPage' object has no attribute 'items'
natehouk commented 1 year ago

One thing to note... if I login and authenticate to a superuser account using the normal admin login page (http://localhost:3000/admin/) and then access the iommi admin page (http://localhost:3000/iommi-admin/) then it works and I am logged in.

CleanShot 2023-08-09 at 07 14 51

However, if I logout, and then try to access the iommi admin page again (http://localhost:3000/iommi-admin/) then I get the same error from above:

CleanShot 2023-08-09 at 07 15 51

boxed commented 1 year ago

Looks like you are missing 'iommi.middleware' in MIDDLEWARE.

natehouk commented 1 year ago

I had to remove iommi.middleware in MIDDLEWARE because I a have Django configured with ATOMIC_REQUEST=True in order to use database transactions. I removed the middleware at the request of this exception from Iommi:

'The iommi middleware is unable to retain atomic transactions. Disable ATOMIC_REQUEST for database connections (<database>) or remove middleware and use the @iommi_render decorator on the views instead.'

Therefore, I removed iommi.middleware and use the @iommi_render decorator on the views as instructed.

Is this configuration not compatible with the built in Iommi Admin?

boxed commented 1 year ago

Seems not.. @jlubcke do you have some comment on this? As this feature is something you use.

jlubcke commented 1 year ago

We use it, but not the login/logout parts. I should be an easy fix I think.