Skip to content
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

HEAD request results in "405 Method Not Allowed" #4864

Closed
matwey opened this issue Jan 30, 2017 · 7 comments
Closed

HEAD request results in "405 Method Not Allowed" #4864

matwey opened this issue Jan 30, 2017 · 7 comments
Labels
Milestone

Comments

@matwey
Copy link

matwey commented Jan 30, 2017

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')...
@matwey
Copy link
Author

matwey commented Feb 8, 2017

Any news? Maybe some additional info is required?

@tomchristie tomchristie added this to the 3.5.4 Release milestone Feb 8, 2017
@tomchristie
Copy link
Member

tomchristie commented Feb 8, 2017

It's on the backlog - I'll take a look at it in due course 😄

@tomchristie
Copy link
Member

tomchristie commented Mar 10, 2017

Confirmed.

image

@tomchristie tomchristie changed the title HEAD request is failed at 3.5.x HEAD request results in "405 Method Not Allowed" Mar 10, 2017
@zastupailo
Copy link

zastupailo commented Mar 13, 2017

I think the problem was introduced by changes in viewsets.py in #4513.
Adding these lines back fixed the bug:

 if hasattr(self, 'get') and not hasattr(self, 'head'):
    self.head = self.get

@tomchristie
Copy link
Member

tomchristie commented Mar 13, 2017

Thanks @azastupailo!

@xordoquy
Copy link
Collaborator

xordoquy commented Mar 13, 2017

Good catch, now we have to understand why there was that comment :)

@tomchristie
Copy link
Member

tomchristie commented Mar 13, 2017

We'll have had something similar for views, which can be removed post 1.5, which erroneously also ended up as a comment against viewsets, which work differently.

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

No branches or pull requests

4 participants