Permalink
Browse files

newforms-admin: Merged from trunk up to [7928].

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7937 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent c546b55 commit dce7cfee16094cb1dd060fb4d90ab73f62069317 @brosner brosner committed Jul 16, 2008
@@ -60,7 +60,6 @@ def load_middleware(self):
def get_response(self, request):
"Returns an HttpResponse object for the given HttpRequest"
from django.core import exceptions, urlresolvers
- from django.core.mail import mail_admins
from django.conf import settings
# Apply request middleware
@@ -122,21 +121,36 @@ def get_response(self, request):
if settings.DEBUG_PROPAGATE_EXCEPTIONS:
raise
- elif settings.DEBUG:
- from django.views import debug
- return debug.technical_500_response(request, *exc_info)
- else:
- # When DEBUG is False, send an error message to the admins.
- subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
- try:
- request_repr = repr(request)
- except:
- request_repr = "Request repr() unavailable"
- message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
- mail_admins(subject, message, fail_silently=True)
- # Return an HttpResponse that displays a friendly error message.
- callback, param_dict = resolver.resolve500()
- return callback(request, **param_dict)
+ return self.handle_uncaught_exception(request, resolver, exc_info)
+
+ def handle_uncaught_exception(self, request, resolver, exc_info):
+ """
+ Processing for any otherwise uncaught exceptions (those that will
+ generate HTTP 500 responses). Can be overridden by subclasses who want
+ customised 500 handling.
+
+ Be *very* careful when overriding this because the error could be
+ caused by anything, so assuming something like the database is always
+ available would be an error.
+ """
+ from django.conf import settings
+ from django.core.mail import mail_admins
+
+ if settings.DEBUG:
+ from django.views import debug
+ return debug.technical_500_response(request, *exc_info)
+
+ # When DEBUG is False, send an error message to the admins.
+ subject = 'Error (%s IP): %s' % ((request.META.get('REMOTE_ADDR') in settings.INTERNAL_IPS and 'internal' or 'EXTERNAL'), request.path)
+ try:
+ request_repr = repr(request)
+ except:
+ request_repr = "Request repr() unavailable"
+ message = "%s\n\n%s" % (self._get_traceback(exc_info), request_repr)
+ mail_admins(subject, message, fail_silently=True)
+ # Return an HttpResponse that displays a friendly error message.
+ callback, param_dict = resolver.resolve500()
+ return callback(request, **param_dict)
def _get_traceback(self, exc_info=None):
"Helper function to return the traceback as a string"
@@ -53,6 +53,7 @@ class BaseDatabaseFeatures(object):
time_field_needs_date = False
interprets_empty_strings_as_nulls = False
date_field_supports_time_value = True
+ can_use_chunked_reads = True
class BaseDatabaseOperations(object):
"""
@@ -40,6 +40,11 @@
class DatabaseFeatures(BaseDatabaseFeatures):
supports_constraints = False
+ # SQLite cannot handle us only partially reading from a cursor's result set
+ # and then writing the same rows to the database in another cursor. This
+ # setting ensures we always read result sets fully into memory all in one
+ # go.
+ can_use_chunked_reads = False
class DatabaseOperations(BaseDatabaseOperations):
def date_extract_sql(self, lookup_type, field_name):
@@ -1616,10 +1616,16 @@ def execute_sql(self, result_type=MULTI):
# The MULTI case.
if self.ordering_aliases:
- return order_modified_iter(cursor, len(self.ordering_aliases),
+ result = order_modified_iter(cursor, len(self.ordering_aliases),
self.connection.features.empty_fetchmany_value)
- return iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
+ result = iter((lambda: cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)),
self.connection.features.empty_fetchmany_value)
+ if not self.connection.features.can_use_chunked_reads:
+ # If we are using non-chunked reads, we return the same data
+ # structure as normally, but ensure it is all read into memory
+ # before going any further.
+ return list(result)
+ return result
# Use the backend's custom Query class if it defines one. Otherwise, use the
# default.
Oops, something went wrong.

0 comments on commit dce7cfe

Please sign in to comment.