Opened 8 years ago

Closed 8 years ago

#27389 closed Cleanup/optimization (wontfix)

Cannot use QueryDict without configuring settings first

Reported by: Jaap Roes Owned by: nobody
Component: HTTP handling Version: dev
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

This is not really a bug, but I was surprised by this behaviour:

>>> from django.http import QueryDict
>>> q = QueryDict('a=1&a=2&b=3&c=4&c=5&d')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/path/to/lib/python3.4/site-packages/django/http/request.py", line 377, in __init__
    encoding = settings.DEFAULT_CHARSET
  File "/path/to/lib/python3.4/site-packages/django/conf/__init__.py", line 53, in __getattr__
    self._setup(name)
  File "/path/to/lib/python3.4/site-packages/django/conf/__init__.py", line 39, in _setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_CHARSET, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

The QueryDict implementation relies on two Django settings DEFAULT_CHARSET and DATA_UPLOAD_MAX_NUMBER_FIELDS, both have sane defaults ('utf-8' and 1000) and are probably rarely overruled in user settings. Would it be acceptable to just use these values if settings aren't configured?

Change History (3)

comment:1 by Tim Graham, 8 years ago

I guess it's a question of how much effort it will take and if it's possible to write tests. Would you like to offer a patch?

Last edited 8 years ago by Tim Graham (previous) (diff)

comment:2 by Claude Paroz, 8 years ago

We probably need a use case also.

comment:3 by Jaap Roes, 8 years ago

Resolution: wontfix
Status: newclosed

No real use case. I was just trying to use the QueryDict in simple quick (throwaway) python script and was surprised it didn't work standalone.

I'll resolve it as wontfix because I cannot be bothered to write a patch ;-)

Note: See TracTickets for help on using tickets.
Back to Top