Skip to content
This repository has been archived by the owner on Jun 11, 2018. It is now read-only.

Django: use request.get_raw_uri to work around DisallowedHost #143

Merged
merged 1 commit into from
Dec 20, 2016

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Nov 22, 2016

Django throws DisallowedHost when using
request.build_absolute_uri(), where the host is not in the
ALLOWED_HOSTS setting.

This prevents Opbeat then from logging the event properly.

Ref: https://code.djangoproject.com/ticket/27506

Django throws `DisallowedHost` when using
`request.build_absolute_uri()`, where the host is not in the
ALLOWED_HOSTS setting.

This prevents Opbeat then from logging the event properly.

Ref: https://code.djangoproject.com/ticket/27506
@blueyed
Copy link
Contributor Author

blueyed commented Nov 22, 2016

CI is broken, py.test fails:

pkg_resources.VersionConflict: (kombu 3.0.37 (/home/travis/virtualenv/python3.4.2/lib/python3.4/site-packages), Requirement.parse('kombu<5.0,>=4.0'))

# Django 1.9.
get_raw_uri = request.get_raw_uri
except AttributeError:
# Requires host to be in ALLOWED_HOSTS.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, the "Django 1.9" comment isn't clear if that's for older versions or newer versions. I'd write:

except AttributeError:  # Django ≤ 1.8

Of course, I'd also like to see a test that demonstrates the usefulness of the change, but I'm not an opbeat committer and so not familiar with their policies.

beniwohli added a commit that referenced this pull request Dec 20, 2016
Manually verified that the test fails with an exception without the patch
@beniwohli beniwohli merged commit 47846da into opbeat:master Dec 20, 2016
@blueyed blueyed deleted the django-use-get_raw_uri branch December 20, 2016 21:16
@blueyed blueyed restored the django-use-get_raw_uri branch December 21, 2016 10:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants