Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Support older django versions (Pull request for Issue #221) #222

Closed
wants to merge 2 commits into from

3 participants

@amgibson

I've tried to allow support for various versions of Django. I don't know whether this is the best way to do it though.

Note that StreamingHttpResponse was new in Django 1.5, so I think the current base repo version of the code will only work with Django 1.5 or later.

I've only tested the change with Django 1.2.4.

@amgibson amgibson referenced this pull request
Closed

Traceback in Django 1.2.4 #221

@plq

this needs to be:

retval = self.HttpResponseObject()
@plq
Owner

I'm looking at the changes you made, was this working at all?

@amgibson

I got various errors when trying to use the version before my changes. It looked to me like the code wouldn't work irrespective of Django version. For example the call to 'set_response' passed 'self' as the first parameter which didn't look right to me.

@plq
Owner

On 03/27/13 13:44, amgibson wrote:

I'm using Soap as the input protocol, so my requests are post requests and it's working OK.

Are you sure? That's where the input stream comes from, you do need 'wsgi.input' in request environment.

@plq plq referenced this pull request from a commit in plq/spyne
@plq plq fix DjangoApplication #222 bbfc46c
@plq plq referenced this pull request from a commit in plq/spyne
@plq plq Make StreamingHttpReponse optional. #222 ddc7769
@plq
Owner

Well, the rpctest in examples now work. Looking forward to your patch for a fix for django 1.2

@amgibson

I'm using Soap as the input protocol, so my requests are post requests and it's working OK.

Are you sure? That's where the input stream comes from, you do need 'wsgi.input' in request environment.

In my case, wsgi.input is already set in the request environment (to a socket._fileobject object). This is the case both when I make a post request to use a service and when making a get request to get the WSDL.

@plq
Owner

Indeed.

Interesting.

I'm not too familiar with the django wrapper, I didn't write it. I'll just remove wsgi.input assingment regardless of django version. Are you OK with this?

@amgibson

Removing the line is OK for me. However, I don't know whether removing it will cause problems with later versions of django.

@plq
Owner

Tested with 1.4.2, seems OK.

@plq
Owner

Tested with 1.5.0, seems OK.

@plq
Owner

Well, commented them out.

Thank you very much for your time.

@plq plq closed this
@plq plq referenced this pull request from a commit in plq/spyne
@plq plq Remove 'wsgi.input' assignment in django wrapper. #222 f4350ea
@amgibson

I had been running with the wsgi.multithread assignment. Having seen your recent commit, I tried with the wsgi.multithread assignment commented out and that seems to work OK on django 1.2.4.

Thank you for fixing this issue.

@plq
Owner

I have no idea what that means. Spyne should be able to run in multithreaded mode, so I thought I should rather comment it out. I could not find concrete data on its meaning, I'd be happy to include it if it's indeed needed.

It's been a pleasure :)

@plq plq referenced this pull request from a commit in plq/spyne
@plq plq Update django version in the readme. #222 5c9e6d9
@dmugtasimov

if these are commented
#environ['wsgi.input'] = request
#environ['wsgi.multithread'] = False
then Django hangs instead of returning HTTP 500 with proper description. Once I uncomment both of them it properly fails returning HTTP 500.

This is for Django 1.4.0, for 1.4.2 is also reproduced.

It seems to me that these two should not have been violently commented out ;)

Probably, this is related with https://techknowhow.library.emory.edu/blogs/branker/2010/07/30/django-lxml-wsgi-and-python-sub-interpreter-magic .

@plq
Owner

Hi,

This is getting a bit wishy-washy. Could someone please contribute a proper test suite for django integration?

Best,

@plq plq reopened this
@plq plq closed this
@plq plq referenced this pull request
Closed

Django doesn't show errors #259

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. @amgibson
  2. @amgibson

    Add back deleted docstring

    amgibson authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 13 deletions.
  1. +17 −13 spyne/server/django.py
View
30 spyne/server/django.py
@@ -24,19 +24,19 @@
from __future__ import absolute_import
+from django import VERSION as django_version
+
+django_version_gte_1_3 = django_version[0] >=1 and django_version[1] >=3 # Django 1.3 or higher
+django_version_gte_1_5 = django_version[0] >=1 and django_version[1] >=5 # Django 1.5 or higher
+
from django.http import HttpResponse
-from django.http import StreamingHttpResponse
from spyne.server.wsgi import WsgiApplication
-
class DjangoApplication(WsgiApplication):
"""You should use this for regular RPC."""
-
- HttpResponseObject = HttpResponse
-
def __call__(self, request):
- retval = self.HttpResponse
+ retval = HttpResponse()
def start_response(status, headers):
status, reason = status.split(' ', 1)
@@ -46,21 +46,25 @@ def start_response(status, headers):
retval[header] = value
environ = request.META.copy()
- environ['wsgi.input'] = request
+ if django_version_gte_1_3:
+ environ['wsgi.input'] = request
environ['wsgi.multithread'] = False
response = WsgiApplication.__call__(self, environ, start_response)
- self.set_response(self, retval, response)
+ self.set_response(retval, response)
return retval
def set_response(self, retval, response):
retval.content = ''.join(response)
+if django_version_gte_1_5:
+ # StreamingHttpResponse was new in Django 1.5
+ from django.http import StreamingHttpResponse
-class StreamingDjangoApplication(DjangoApplication):
- """You should use this when you're generating HUGE data as response."""
+ class StreamingDjangoApplication(DjangoApplication):
+ """You should use this when you're generating HUGE data as response."""
- HttpResponseObject = StreamingHttpResponse
- def set_response(self, retval, response):
- retval.streaming_content = response
+ HttpResponseObject = StreamingHttpResponse
+ def set_response(self, retval, response):
+ retval.streaming_content = response
Something went wrong with that request. Please try again.