Migrating django.dispatch.dispatcher from Django 0.96 to 1.0.2

How to execute the following (Django 0.96) dispatch 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) 

By the way, this code is from a Google article on using Django in GAE . Unfortunately, the send code in Django was rewritten between 0.96 and 1.0, and the Google example does not work with Django 1.0.

Of course, the Django people provided a useful guide on how to make this particular migration, but I am not sufficiently keen on the figure of it at the moment .: O)

Thank you for reading.

Brian

+4
source share
1 answer

The main difference is that you no longer ask the dispatcher to connect you to a certain signal, you directly request a signal. Therefore, it looks 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) 
+5
source

All Articles