gh-134759: UnboundLocalError in email.message.Message.get_payload#136071
gh-134759: UnboundLocalError in email.message.Message.get_payload#136071picnixz merged 13 commits intopython:mainfrom
UnboundLocalError in email.message.Message.get_payload#136071Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Misc/NEWS.d/next/Library/2025-06-28-11-32-57.gh-issue-134759.AjjKcG.rst
Outdated
Show resolved
Hide resolved
…jjKcG.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Lib/test/test_email/test_message.py
Outdated
| def test_get_bytes_payload_with_quoted_printable_encoding(self): | ||
| payload = b'Some payload' |
There was a problem hiding this comment.
| def test_get_bytes_payload_with_quoted_printable_encoding(self): | |
| payload = b'Some payload' | |
| def test_get_bytes_payload_with_quoted_printable_encoding(self): | |
| # See https://github.com/python/cpython/issues/134759. | |
| payload = b'Some payload' |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
We can use the following for only using public methods:
payload = memoryview(b'Some payload')
m = self._make_message()
m.add_header('Content-Transfer-Encoding', 'quoted-printable')
m.set_payload(payload)
self.assertEqual(m.get_payload(decode=True), payload)There was a problem hiding this comment.
Yes, I was trying to reproduce bug with "public" method .set_payload(). I'm achieved that by passing BytesIO(b"Some payload") buffer but was not sure about correct arg type of .set_payload() (typeshed want object only with the .decode() method), so came up to put bytes directly.
I'll change the way you suggest, no problem :)
There was a problem hiding this comment.
Yeah, decode() is not present on memoryview but it's a buffer-like protocol so I think it should be fine. However, this may be a side-effect of the current implementation :) (also, the current implementation only does duck typing, not true isinstance() checks when setting the payload)
|
As a bugfix I think we can keep this but in a follow-up PR I think we should ensure that we are only having a list, str or bytes or handle buffer objects by wrapping them into bytes. |
Got it. If nobody mind I can open an issue (or keep in #134759 ?) and take it in work :) |
|
I'm travelling for now but a separate issue for discussion would be better. It could break backwards compatibility so we should be careful. |
IMO even contributors fixing a single typo can be added to this file so no worry! |
|
Thanks @skv0zsneg for the PR, and @picnixz for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14. |
…t_payload` (pythonGH-136071) (cherry picked from commit 25335d2) Co-authored-by: Kliment Lamonov <klimentlamonov@yandex.ru> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
GH-136579 is a backport of this pull request to the 3.14 branch. |
…t_payload` (pythonGH-136071) (cherry picked from commit 25335d2) Co-authored-by: Kliment Lamonov <klimentlamonov@yandex.ru> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
GH-136580 is a backport of this pull request to the 3.13 branch. |
…t_payload` (python#136071) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…t_payload` (python#136071) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…t_payload` (python#136071) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…t_payload` (python#136071) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…sage.get_payload` (pythonGH-136071) (python#136579) pythongh-134759: fix `UnboundLocalError` in `email.message.Message.get_payload` (pythonGH-136071) (cherry picked from commit 25335d2) Co-authored-by: Kliment Lamonov <klimentlamonov@yandex.ru> Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Hello!
I worked on #134759 and was able to reproduce the
UnboundLocalErrorby passing bytes payload directly to_payload. I'm not sure can we do it in a "public" way, like throw.set_payload()but if payload some how become bytes (and content-transfer-encoding is equal quoted-printable) it is now not falling :)I'm also add myself to ACKS list, but not sure is my changes enough for it. If you say I'll remove myself with no questions.
UnboundLocalErrorinemail.message.Message.get_payload#134759