Skip to content

Attribute Error with Request Panel #1150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MiStErLu opened this issue Apr 2, 2019 · 8 comments
Closed

Attribute Error with Request Panel #1150

MiStErLu opened this issue Apr 2, 2019 · 8 comments

Comments

@MiStErLu
Copy link

MiStErLu commented Apr 2, 2019

Hi,

I found a bug with the Request Panel :
If i use a "Paginator" object and if i click on the next link i got this error

If i disable Request Panel, it work.
I use : django-debug-toolbar==1.11

Environment:

Request Method: GET
Request URL: http://127.0.0.1:8000/search/sets?page=2

Django Version: 2.1.7
Python Version: 3.6.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'hijack',
'compat',
'ajax_select',
'ckeditor',
'ckeditor_uploader',
'mathfilters',
'captcha',
'django_crontab',
'monapp',
'monapp.apps.search',
'monapp.apps.manage',
'monapp.apps.buy',
'hijack_admin',
'coverage',
'debug_toolbar')
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',
'debug_toolbar.middleware.DebugToolbarMiddleware']

Traceback:

File "/home/xxxxxx/.virtualenvs/monapp/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)

File "/home/xxxxxx/.virtualenvs/monapp/lib/python3.6/site-packages/django/utils/deprecation.py" in call
93. response = self.process_response(request, response)

File "/home/xxxxxx/.virtualenvs/monapp/lib/python3.6/site-packages/debug_toolbar/middleware.py" in process_response
133. panel.generate_stats(request, response)

File "/home/xxxxxx/.virtualenvs/monapp/lib/python3.6/site-packages/debug_toolbar/panels/request.py" in generate_stats
33. "post": [(k, request.POST.getlist(k)) for k in sorted(request.POST)],

File "/home/xxxxxx/.virtualenvs/monapp/lib/python3.6/site-packages/debug_toolbar/panels/request.py" in
33. "post": [(k, request.POST.getlist(k)) for k in sorted(request.POST)],

Exception Type: AttributeError at /search/sets
Exception Value: 'dict' object has no attribute 'getlist'

@matthiask
Copy link
Member

Someone or something is replacing the request.POST QueryDict with a dict. Do you have any idea what might be replacing request.POST with an incompatible data type?

@MiStErLu
Copy link
Author

MiStErLu commented Apr 3, 2019

It probably came from this code :

@login_required
def search_sets(request):
if not request.method == 'POST' and 'page' in request.GET:
if 'search-sets-post' in request.session:
request.POST = request.session['search-sets-post']
request.method = 'POST'

if request.method == 'POST':
    # create a form instance and populate it with data from the request:
    form = SetSearch(request.POST)
    request.session['search-sets-post'] = request.POST

@matthiask
Copy link
Member

Yes, that doesn't look right.

@tim-schilling
Copy link
Member

@MiStErLu Did changing that method fix your problem?

@MiStErLu
Copy link
Author

@tim-schilling I don't change my method, for testing this functionality i disable django-debug-toolbar. In production, it's not enable

@tim-schilling
Copy link
Member

Correct, but you shouldn't be doing request.POST = request.session['search-sets-post']. request.POST, request.GET and request.FILES should only be read from in the views, not assigned to.

@jdufresne
Copy link
Contributor

I agree. This is a incorrect use of the Django request API and not the fault of Debug Toolbar. I think the view above should be considered to have a bug and fixed. I'm closing, but if you can demonstrate a bug in Debug Toolbar, please provide more detail.

@mark-mishyn
Copy link

mark-mishyn commented Nov 23, 2020

Hi guys.

I have the same issue after toolbar update from 2 to 3 version (tried different 3.X versions)

Eventually I could not find the place where request.POST is set to regular dict.

I came up with the following hack/fix in debug_toolbar/panel/request.py

def generate_stats(self, request, response):
    from django.http import QueryDict
        
    if isinstance(request.POST, dict):
        query_dict = QueryDict('', mutable=True)
        query_dict.update(request.POST)
        request.POST = query_dict
        ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants