Skip to content

Request must inherit from HttpRequest #128

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

Closed
sebpiq opened this issue Jan 13, 2012 · 3 comments
Closed

Request must inherit from HttpRequest #128

sebpiq opened this issue Jan 13, 2012 · 3 comments

Comments

@sebpiq
Copy link
Contributor

sebpiq commented Jan 13, 2012

Request must become a subclass of Django's HttpRequest.
.DATA, .FILES, .auth and .method, previously available on views inheriting from RequestMixin will become request.DATA, request.FILES, request.method... Regular attributes on the request (eg. .META etc.) will still be available.
Also, .CONTENT probably needs to disappear and won't be provided by the new Request class.

@flashingpumpkin
Copy link
Contributor

I'd love to see that.

Also, I'd love to see .CONTENT disappear because it's a property and a bit too magic-y. Validation shouldn't happen when looking at .CONTENT, but when calling .validate or some such.

@sebpiq
Copy link
Contributor Author

sebpiq commented Jan 22, 2012

I started working on that.

@sebpiq
Copy link
Contributor Author

sebpiq commented Jan 22, 2012

Need some advice here.

I can think of 3 approaches for doing that:

  1. Dynamically attaching new properties (.DATA, ...) to the request.
    + no need to copy the whole request object
    - dynamically attaching properties to every request is maybe not the most efficient thing, and really hackish
    - a bit complicated
  2. Generate subclass of the request class (done only once), then for each new request, create new instance of our own request class, and copy original request to this new instance.
    + seems the cleanest solution to me, since we are indeed using a subclass of the request
    - requires to copy the whole __dict__ for every request
  3. Create a subclass of HttpRequest, which takes a request as only argument, and acts as a wrapper for it : it provides new properties on the wrapped request, and delegates the rest to the wrapped request.
    + no copy, no dynamically attaching properties, so probably the most performant
    - very hackish, and makes the subclassing of HttpRequest quite meaningless

I chose the 2. What are your opinions ?

treyhunner pushed a commit to treyhunner/django-rest-framework that referenced this issue Sep 16, 2015
Defining requires_model_validation as False on compress command, for offline compression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants