HEAD request results in "405 Method Not Allowed" · Issue #4864 · encode/django-rest-framework (original) (raw)

Steps to reproduce

Hello,

Please find minimal testing project at https://github.com/matwey/drf-head
Issue is that HEAD method to retrieve has been silently disabled or broken in 3.5.x.
At least an notification in changelog and docs should be provided about the preferred way to bring old behavior back.

Django 1.10.5 is used.

Expected behavior (3.4.7)

> pip show djangorestframework
---
Name: djangorestframework
Version: 3.4.7
Location: /home/matwey/temp/venv/lib/python3.4/site-packages
Requires: 
(venv)matwey@epsilon:~/temp/drf_test> python runtests.py 
Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...
Operations to perform:
  Synchronize unmigrated apps: rest_framework, theapp
  Apply all migrations: auth, authtoken, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Creating table theapp_model
    Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying authtoken.0001_initial... OK
  Applying authtoken.0002_auto_20160226_1747... OK
test_model_head1 (tests.test.ModelTest) ... ok

----------------------------------------------------------------------
Ran 1 test in 0.075s

OK
Destroying test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...

Actual behavior (3.5.3)

> pip show djangorestframework          
---
Name: djangorestframework
Version: 3.5.3
Location: /home/matwey/temp/venv/lib/python3.4/site-packages
Requires: 
(venv)matwey@epsilon:~/temp/drf_test> python runtests.py                    
Creating test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...
Operations to perform:
  Synchronize unmigrated apps: rest_framework, theapp
  Apply all migrations: auth, authtoken, contenttypes
Synchronizing apps without migrations:
  Creating tables...
    Creating table theapp_model
    Running deferred SQL...
Running migrations:
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying auth.0008_alter_user_username_max_length... OK
  Applying authtoken.0001_initial... OK
  Applying authtoken.0002_auto_20160226_1747... OK
test_model_head1 (tests.test.ModelTest) ... FAIL

======================================================================
FAIL: test_model_head1 (tests.test.ModelTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/matwey/temp/drf_test/tests/test.py", line 18, in test_model_head1
    self.assertEqual(response.status_code, status.HTTP_200_OK)
AssertionError: 405 != 200

----------------------------------------------------------------------
Ran 1 test in 0.083s

FAILED (failures=1)
Destroying test database for alias 'default' ('file:memorydb_default?mode=memory&cache=shared')...