#16245: send_robust should include traceback in response when Exception occurs

73 views
Skip to first unread message

unai

unread,
Oct 30, 2013, 5:23:07 AM10/30/13
to django-d...@googlegroups.com
Hi everybody!

I'm trying to defrost the ticket #16245 that says that
`django.dispatch.dispatcher.Signal.send_robust` should include not only the
exception but also the traceback if something goes wrong.

At this moment, `send_robust` returns a list of (receiver, exception) tuples so
that...

for receiver, exc in my_signal.send_robust():
...

Now, this ticket doubts between two possible solutions. The first of them is
returning a `(receiver, (type, exception, traceback))` made by
`(receiver, sys.exc_info())` tuple if `exc_info` is True:

for receiver, (typ, exc, tbk) in my_signal.send_robust(exc_info=True):
...

The second solution is to attach the traceback to the exception, a la Python 3,
at its `__traceback__` attribute.

The two solutions are backwards compatible. Personally, I prefer the second one
because it's the way to go on Python 3, it doesn't add extra parameters for
maintaining backwards compatibility and doesn't return a messy list of tuple
of tuples.

But there's already a patch with tests from two years ago implementing solution
#1. So what do you think? Do I try to recover the patch with the first solution
or do I go with the second one?

Yours sincerely,
Unai
signature.asc

Shai Berger

unread,
Oct 30, 2013, 3:08:13 PM10/30/13
to django-d...@googlegroups.com
On Wednesday 30 October 2013 11:23:07 unai wrote:
>
> Now, this ticket doubts between two possible solutions. The first of them
> is returning a `(receiver, (type, exception, traceback))` made by
> `(receiver, sys.exc_info())` tuple if `exc_info` is True:
>
> for receiver, (typ, exc, tbk) in my_signal.send_robust(exc_info=True):
> ...
>
> The second solution is to attach the traceback to the exception, a la
> Python 3, at its `__traceback__` attribute.
>
> The two solutions are backwards compatible. Personally, I prefer the second
> one because it's the way to go on Python 3, it doesn't add extra
> parameters for maintaining backwards compatibility and doesn't return a
> messy list of tuple of tuples.
>
> But there's already a patch with tests from two years ago implementing
> solution #1. So what do you think? Do I try to recover the patch with the
> first solution or do I go with the second one?
>
I wouldn't go telling you to do more work than you think is necessary, but if
you're willing to do eithr, I'd prefer to see the second solution in Django;
for all the reasons you gave, plus it is "more backward compatible": Assume I
have some code doing

for receiver, response in my_signal.send_robust(sender):
if isinstance(response, Exception):
my_error_signal.send_robust(sender, exc=response)

With the second solution, I only need to fix the receivers of the error signal
to enjoy the benefits; With the first, I'll need to fix both the receivers and
the signal-sending code, which may be out of my control.

Shai.

unai

unread,
Oct 30, 2013, 8:13:55 PM10/30/13
to django-d...@googlegroups.com
> I wouldn't go telling you to do more work than you think is
> necessary, but if you're willing to do eithr, I'd prefer to see the
> second solution in Django; for all the reasons you gave, plus it is
> "more backward compatible": Assume I have some code doing
>
> for receiver, response in my_signal.send_robust(sender):
> if isinstance(response, Exception):
> my_error_signal.send_robust(sender, exc=response)
>
> With the second solution, I only need to fix the receivers of the
> error signal to enjoy the benefits; With the first, I'll need to fix
> both the receivers and the signal-sending code, which may be out of
> my control.

Patch on its way then!


--
unai
signature.asc
Reply all
Reply to author
Forward
0 new messages