8000 gh-134759: `UnboundLocalError` in `email.message.Message.get_payload` by skv0zsneg · Pull Request #136071 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-134759: UnboundLocalError in email.message.Message.get_payload #136071

New issue

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

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

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

skv0zsneg
Copy link
@skv0zsneg skv0zsneg commented Jun 28, 2025

Hello!

I worked on #134759 and was able to reproduce the UnboundLocalError by 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.

@skv0zsneg skv0zsneg requested a review from a team as a code owner June 28, 2025 11:26
@python-cla-bot
Copy link
python-cla-bot bot commented Jun 28, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link
bedevere-app bot commented Jun 28, 2025

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 skip news label instead.

@picnixz picnixz added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jun 28, 2025
Copy link
Member
@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment on lines 1058 to 1059
def test_get_bytes_payload_with_quoted_printable_encoding(self):
payload = b'Some payload'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting merge needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0