Django

Code

Show
Ignore:
Timestamp:
08/25/08 13:24:05 (3 months ago)
Author:
jacob
Message:

Fixed #8285: signal handlers that aren't functions work under DEBUG. This slightly loosens the sanity check, but things that are valid under production shouldn't fail under debug.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/dispatch/dispatcher.py

    r8291 r8546  
    6464        from django.conf import settings 
    6565         
     66        # If DEBUG is on, check that we got a good receiver 
    6667        if settings.DEBUG: 
    6768            import inspect 
    68             assert inspect.getargspec(receiver)[2] is not None, \ 
    69                 "Signal receivers must accept keyword arguments (**kwargs)." 
     69            assert callable(receiver), "Signal receivers must be callable." 
     70             
     71            # Check for **kwargs 
     72            # Not all callables are inspectable with getargspec, so we'll 
     73            # try a couple different ways but in the end fall back on assuming 
     74            # it is -- we don't want to prevent registration of valid but weird 
     75            # callables. 
     76            try: 
     77                argspec = inspect.getargspec(receiver) 
     78            except TypeError: 
     79                try: 
     80                    argspec = inspect.getargspec(receiver.__call__) 
     81                except (TypeError, AttributeError): 
     82                    argspec = None 
     83            if argspec: 
     84                assert argspec[2] is not None, \ 
     85                    "Signal receivers must accept keyword arguments (**kwargs)." 
    7086         
    7187        if dispatch_uid: