Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#16412 closed Cleanup/optimization (fixed)

Disabling an 'django.contrib.sites' app, causes error in tests with django.contrib.auth.tests.forms.PasswordResetFormTest

Reported by: haras Owned by: nobody
Component: contrib.auth Version: master
Severity: Normal Keywords:
Cc: djangoproject.com@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by ramiro)

Try disabling an 'django.contrib.sites' app, (which as it is a contrib app, should be an optional), and you'll get an error in tests with django.contrib.auth.tests.forms.PasswordResetFormTest.

Attachments (1)

16412.diff (613 bytes) - added by aaugustin 4 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 Changed 4 years ago by d0ugal

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

While the contrib apps should be optional, they do depend on each other. contrib.auth requires contrib.sites.

comment:2 Changed 4 years ago by haras

I am not sure, I have been using contrib.auth without contrib.sites for a few years now.

comment:3 Changed 4 years ago by d0ugal

Hmm, maybe I'm wrong then. Feel free to re-open but you should provide more information including the traceback from the failing test.

comment:4 Changed 4 years ago by haras

  • Resolution invalid deleted
  • Status changed from closed to reopened

Creating test database for alias 'default'...
..............................................................E.................
................................................................................
................................................................................
................................................................................
......
======================================================================
ERROR: test_custom_email_subject (django.contrib.auth.tests.forms.PasswordResetFormTest)


Traceback (most recent call last):

File "C:\Python27\Lib\site-packages\django\contrib\auth\tests\forms.py", line 264, in test_custom_email_subject

form.save()

File "C:\Python27\Lib\site-packages\django\contrib\auth\forms.py", line 138, in save

current_site = get_current_site(request)

File "C:\Python27\Lib\site-packages\django\contrib\sites\models.py", line 94, in get_current_site

current_site = RequestSite(request)

File "C:\Python27\Lib\site-packages\django\contrib\sites\models.py", line 74, in init

self.domain = self.name = request.get_host()

AttributeError: 'NoneType' object has no attribute 'get_host'


Ran 326 tests in 5.113s

FAILED (errors=1)
Destroying test database for alias 'default'...

Version 0, edited 4 years ago by haras (next)

comment:5 Changed 4 years ago by haras

it is fully functional without django.contrib.sites app, no errors, but this one test fails.

comment:6 Changed 4 years ago by ramiro

What depends on the contrib.sites contrib apps is the contrib.auth.forms module. It changed in [13980] but it it already depended on it.

What tests are you running?

comment:7 Changed 4 years ago by haras

python manage.py test in my project root directory

comment:8 Changed 4 years ago by aaugustin

  • Easy pickings unset
  • Has patch set
  • Severity changed from Release blocker to Normal
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from Bug to Cleanup/optimization

django.contrib.auth uses the get_current_site method of django.contrib.sites, which is safe to use, whether the sites framework is or isn't enabled.

However, when the sites framework isn't enabled, this method must receive the request in argument. In test_custom_email_subject, there is no request available, and the test crashes. Attached patch fixes this (and avoids relying on the default name of the default site).

Changed 4 years ago by aaugustin

comment:9 Changed 4 years ago by julien

  • Needs tests set

comment:10 Changed 3 years ago by anonymous coward

Why does this need tests when the diff fixes a failing test (TDD: "...first the developer writes a failing automated test case..."), and the change is 1 line.

comment:11 Changed 3 years ago by ramiro

  • Description modified (diff)

comment:12 Changed 3 years ago by julien

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

True, I had been a bit too quick in my initial judgment and there is no need to write a test here. aaugustin made a good analysis of the issue and the patch seems reasonable. Also the domain_override attribute doesn't seem to be tested yet so that will increase the test suite's coverage. A comment should just be added to that line of code explaining that domain_override needs to be provided in the absence of a request object in case contrib.sites isn't installed -- this can be done on commit.

comment:13 Changed 3 years ago by julien

  • Resolution set to fixed
  • Status changed from reopened to closed

In [16717]:

Fixed #16412 -- Prevented a contrib.auth test from failing in the potential case where contrib.sites was not installed. Thanks to haras for the report and to Aymeric Augustin for the patch.

comment:14 Changed 3 years ago by ramiro

  • Description modified (diff)
  • Summary changed from Disabling an 'django.contrib.sites' app, causes Try disabling an 'django.contrib.sites' app, (which as it is a contrib app, should be an optional), and you'll get an error in tests with django.contrib.auth.tests.forms.PasswordResetFormTest to Disabling an 'django.contrib.sites' app, causes error in tests with django.contrib.auth.tests.forms.PasswordResetFormTest

(just fixing the mess I made with the description and summary of this ticket)

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