I created https://code.djangoproject.com/ticket/26401

> Since the usage of any of the backends requires models

I used the ModelBackend with no issues in Django 1.8 (without auth in 
INSTALLED_APPS). So that is the place I want to refactor.


I'm trying to write a regression test for this, but I can't think of a good 
way to do it. Essentially, I want to ensure 
django.contrib.auth.context_processors/middleware/backends can be imported 
if django.contrib.auth is not in INSTALLED_APPS. Using 
`override_settings(INSTALLED_APPS...)` doesn't "undo" the imports, so 
importing the modules again won't trigger an exception. Any ideas?

On Wednesday, March 23, 2016 at 1:49:32 AM UTC-7, Florian Apolloner wrote:
>
> Oh yes, this is a bug. We should ensure that RemoteUser backend is 
> imported in the middleware itself or that backends.py does not trigger any 
> model imports. Since the usage of any of the backends requires models, the 
> import there seems fine -- I'd import RemoteUserBackend in 
> RemoteUserMiddleware.__init__ -- A patch would be very welcome.
>
> Cheers,
> Florian
>
> On Wednesday, March 23, 2016 at 1:57:41 AM UTC+1, Matt wrote:
>>
>> I like to use the authentication machinery in Django, without explicitly 
>> putting 'django.contrib.auth' in INSTALLED_APPS. This prevents a bunch 
>> of unused tables from being creating in the database.
>>
>> This was possible in earlier version of Django. In 1.8, a spurious 
>> warning was generated, but that was fixed in #24564 (
>> https://groups.google.com/forum/#!searchin/django-developers/$2324564/django-developers/7b4xzkjLFH8/wLJ83Bxa_h4J
>> )
>>
>> In Django 1.9, it doesn't seem possible anymore (see traceback). Using 
>> the auth stuff without installing the app -- is that something we want to 
>> support or not?
>>
>> Traceback (most recent call last):
>>   File "/usr/lib/python3.4/wsgiref/handlers.py", line 137, in run
>>     self.result = application(self.environ, self.start_response)
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py",
>>  
>> line 63, in __call__
>>     return self.application(environ, start_response)
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/core/handlers/wsgi.py",
>>  
>> line 158, in __call__
>>     self.load_middleware()
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/core/handlers/base.py",
>>  
>> line 51, in load_middleware
>>     mw_class = import_string(middleware_path)
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/utils/module_loading.py",
>>  
>> line 20, in import_string
>>     module = import_module(module_path)
>>   File "/usr/lib/python3.4/importlib/__init__.py", line 109, in 
>> import_module
>>     return _bootstrap._gcd_import(name[level:], package, level)
>>   File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
>>   File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
>>   File "<frozen importlib._bootstrap>", line 2203, in 
>> _find_and_load_unlocked
>>   File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
>>   File "<frozen importlib._bootstrap>", line 1129, in _exec
>>   File "<frozen importlib._bootstrap>", line 1448, in exec_module
>>   File "<frozen importlib._bootstrap>", line 321, in 
>> _call_with_frames_removed
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/contrib/auth/middleware.py",
>>  
>> line 3, in <module>
>>     from django.contrib.auth.backends import RemoteUserBackend
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/contrib/auth/backends.py",
>>  
>> line 4, in <module>
>>     from django.contrib.auth.models import Permission
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/contrib/auth/models.py",
>>  
>> line 38, in <module>
>>     class Permission(models.Model):
>>   File "/home/
>> example.com/.venv-bee4e82373367b8524982d09c561f7f1/lib/python3.4/site-packages/django/db/models/base.py",
>>  
>> line 102, in __new__
>>     "INSTALLED_APPS." % (module, name)
>> RuntimeError: Model class django.contrib.auth.models.Permission doesn't 
>> declare an explicit app_label and isn't in an application in INSTALLED_APPS.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/1f687f3e-e850-4a96-a1a6-5b878f2158ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to