Opened 3 years ago

Closed 5 months ago

Last modified 5 months ago

#7679 defect closed duplicate (duplicate)

__traceback__ for spread.pb.CopyableFailure received by a Python3 process

Reported by: Wolfgang Rohdewald Owned by:
Priority: normal Milestone: Python-3.x
Component: core Keywords:
Cc: Branch:
Author:

Description

I have one process raising a UnicodeDecodeError. This is sent over the wire to a Python3 process. That one calls Failure.cleanFailure (traceback see below) which says self.value.__traceback__ = None. But when receiving a UnicodeDecodeError packed into CopyableFailure, self.value is a string, and setting __traceback__ raises AttributeError. The fix in cleanFailure() is simple:

@@ -495,7 +498,7 @@ class Failure:
         exception instance to C{None}.
         """
         self.__dict__ = self.__getstate__()
-        if _PY3:
+        if _PY3 and getattr(self.value, '__traceback__', None):
             self.value.__traceback__ = None

But the first problem is the docstring of cleanFailure() which implies that self.value must always be an exception instance. Is that docstring correct?

This code in cleanFailure() was added with svn r35620 (Port twisted.internet.defer to Python 3).

My traceback:

Unhandled Error
Traceback (most recent call last):
  File "/home/wr/vpn/kajongg/src/twisted/python/log.py", line 102, in callWithLogger
    return callWithContext({"system": lp}, func, *args, **kw)
  File "/home/wr/vpn/kajongg/src/twisted/python/log.py", line 85, in callWithContext
    return context.call({ILogContext: newCtx}, func, *args, **kw)
  File "/home/wr/vpn/kajongg/src/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/home/wr/vpn/kajongg/src/twisted/python/context.py", line 81, in callWithContext
    return func(*args,**kw)
--- <exception caught here> ---
  File "/home/wr/vpn/kajongg/src/twisted/internet/posixbase.py", line 614, in _doReadOrWrite
    why = selectable.doRead()
  File "/home/wr/vpn/kajongg/src/twisted/internet/tcp.py", line 215, in doRead
    return self._dataReceived(data)
  File "/home/wr/vpn/kajongg/src/twisted/internet/tcp.py", line 221, in _dataReceived
    rval = self.protocol.dataReceived(data)
  File "/home/wr/vpn/kajongg/src/twisted/spread/banana.py", line 266, in dataReceived
    gotItem(item)
  File "/home/wr/vpn/kajongg/src/twisted/spread/banana.py", line 187, in gotItem
    self.callExpressionReceived(item)
  File "/home/wr/vpn/kajongg/src/twisted/spread/banana.py", line 150, in callExpressionReceived
    self.expressionReceived(obj)
  File "/home/wr/vpn/kajongg/src/twisted/spread/pb.py", line 591, in expressionReceived
    method(*sexp[1:])
  File "/home/wr/vpn/kajongg/src/twisted/spread/pb.py", line 1016, in proto_error
    d.errback(self.unserialize(fail))
  File "/home/wr/vpn/kajongg/src/twisted/internet/defer.py", line 426, in errback
    self._startRunCallbacks(fail)
  File "/home/wr/vpn/kajongg/src/twisted/internet/defer.py", line 493, in _startRunCallbacks
    self._runCallbacks()
  File "/home/wr/vpn/kajongg/src/twisted/internet/defer.py", line 625, in _runCallbacks
    current.result.cleanFailure()
  File "/home/wr/vpn/kajongg/src/twisted/python/failure.py", line 502, in cleanFailure
    self.value.__traceback__ = None
builtins.AttributeError: 'str' object has no attribute '__traceback__'

where proto_error() calls unserialize with those arguments:

[b'twisted.spread.pb.CopyableFailure', [b'dictionary', [b'count', 8], [b'captureVars', [b'boolean', b'false']], [b'type', b'exceptions.UnicodeDecodeError'], [b'traceback', b'Traceback unavailable\n'], [b'value', b"'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)"], [b'unsafeTracebacks', [b'boolean', b'false']], [b'parents', [b'list', b'exceptions.UnicodeDecodeError', b'exceptions.UnicodeError', b'exceptions.ValueError', b'exceptions.StandardError', b'exceptions.Exception', b'exceptions.BaseException', b'__builtin__.object']], [b'frames', [b'list']], [b'tb', [b'None']], [b'stack', [b'list']]]]}}}

Change History (4)

comment:1 Changed 3 years ago by Glyph

Keywords: review removed

Thanks for the bug report.

This ticket does not appear to have a patch or branch attached though, so it's not ready for review yet.

Perhaps by the "review" keyword you meant you'd like someone to review and discuss it? In that case, please raise it on the mailing list.

comment:2 Changed 5 months ago by Craig Rodrigues

Keywords: py3k removed
Milestone: Python-3.x

comment:3 Changed 5 months ago by Craig Rodrigues

Resolution: duplicate
Status: newclosed

Duplicate of ticket:9057

comment:4 Changed 5 months ago by Glyph

Thanks for finding this and closing this, cleaning up extra open bugs is great.

However, by default, the ticket closed when a duplicate is found should be the higher-numbered ticket. There's generally an exception to this if the higher-numbered one already has a PR (or patch) attached, so it's always nice to note that explicitly if that's the case.

Note: See TracTickets for help on using tickets.