Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix pickling of httpclient.HTTPError subclasses and web.HTTPError #3439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Nov 2, 2024

The args member variable is set by BaseException.__new__ and used by BaseException.__reduce__ for pickling. To avoid interfering with it, we need to avoid calling BaseException.__init__ from classes that have subclasses with incompatible constructors, and rename our own tornado.web.HTTPError.args member.

>>> pickle.loads(pickle.dumps(tornado.simple_httpclient.HTTPTimeoutError("message")))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: HTTPTimeoutError.__init__() takes 2 positional arguments but 4 were given
>>> str(pickle.loads(pickle.dumps(tornado.web.HTTPError(500, "%s", "foo"))))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/anders/python/tornado/tornado/web.py", line 2488, in __str__
    return message + " (" + (self.log_message % self.args) + ")"
                             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~
TypeError: not enough arguments for format string

The `args` member variable is set by `BaseException.__new__` and used
by `BaseException.__reduce__` for pickling.  To avoid interfering with
it, we need to avoid calling `BaseException.__init__` from classes
that have subclasses with incompatible constructors, and rename our
own `tornado.web.HTTPError.args` member.

    >>> pickle.loads(pickle.dumps(tornado.simple_httpclient.HTTPTimeoutError("message")))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: HTTPTimeoutError.__init__() takes 2 positional arguments but 4 were given
    >>> str(pickle.loads(pickle.dumps(tornado.web.HTTPError(500, "%s", "foo"))))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/home/anders/python/tornado/tornado/web.py", line 2488, in __str__
        return message + " (" + (self.log_message % self.args) + ")"
                                 ~~~~~~~~~~~~~~~~~^~~~~~~~~~~
    TypeError: not enough arguments for format string

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant