views:

171

answers:

1

How does one perform the following (Django 0.96) dispatcher hooks in Django 1.0?

import django.dispatch.dispatcher

def log_exception(*args, **kwds):
  logging.exception('Exception in request:')

# Log errors.
django.dispatch.dispatcher.connect(
  log_exception, django.core.signals.got_request_exception)

# Unregister the rollback event handler.
django.dispatch.dispatcher.disconnect(
  django.db._rollback_on_exception,
  django.core.signals.got_request_exception)

Incidentally, this code is from Google's Article on Using Django on GAE. Unfortunately the dispatch code in Django was rewritten between 0.96 and 1.0, and Google's example does not work with Django 1.0.

Of course, the Django people provided a helpful guide on how to do exactly this migration, but I'm not keen enough to figure it out at the moment. :o)

Thanks for reading.

Brian

+3  A: 

The basic difference is that you no longer ask the dispatcher to connect you to some signal, you ask the signal directly. So it would look something like this:

from django.core.signals import got_request_exception
from django.db import _rollback_on_exception

def log_exception(*args, **kwds):
  logging.exception('Exception in request:')

# Log errors.
got_request_exception.connect(log_exception)

# Unregister the rollback event handler.
_rollback_on_exception.disconnect(got_request_exception)
obvio171
Awesome - Thanks. :o)
Brian M. Hunt