bpo-33972: Fix EmailMessage.iter_attachments raising AttributeError. by maxking · Pull Request #14119 · python/cpython (original) (raw)

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 andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation8 Commits4 Checks0 Files changed

Conversation

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})

maxking

When certain malformed messages have content-type set to 'mulitpart/*' but
still have a single part body, iter_attachments can raise AttributeError. This
patch fixes it by returning a None value instead when the body is single part.

https://bugs.python.org/issue33972

@maxking

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.

@maxking

It looks like Docs builds are failing on both Azure and Travis, even though I haven't changed anything in there.

@maxking

mangrisano

@brettcannon

@maxking

Yep, I am not sure what was the reason for it. I moved multiipart/* (invalid rst?) text to multipart/* text, which fixed the tests :)

Or it could be unrelated, I am not sure.

warsaw

# Certain malformed messages can have content type set to `multipart/*`
# but still have single part body, in which case payload.copy() can
# fail with AttributeError.
if not isinstance(payload, list):

Choose a reason for hiding this comment

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

What do you think about catching the AttributeError on .copy() instead of doing a type test here? E.g.:

        try:
            parts = payload.copy()
        except AttributeError:
            return None

? (Also aside, when returning None is part of the API, it's generally better to be explicit.)

Choose a reason for hiding this comment

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

I'll update to catch AttributeError.

It technically doesn't return None, since this is a generator. I don't know if it that makes any sense?

Choose a reason for hiding this comment

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

It is same what other return statements in this method do.

Choose a reason for hiding this comment

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

Cool, thanks! I didn't pick that up from the diff context.

@bedevere-bot

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@maxking

warsaw

@maxking

maxking added a commit to maxking/cpython-1 that referenced this pull request

Jun 25, 2019

@maxking

…rror. (pythonGH-14119)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701)

Co-authored-by: Abhilash Raj maxking@users.noreply.github.com

maxking added a commit to maxking/cpython-1 that referenced this pull request

Jun 25, 2019

@maxking

…rror. (pythonGH-14119)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701)

Co-authored-by: Abhilash Raj maxking@users.noreply.github.com

miss-islington pushed a commit that referenced this pull request

Jun 25, 2019

@maxking @miss-islington

…rror (GH-14119) (GH-14380)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701)

Co-authored-by: Abhilash Raj maxking@users.noreply.github.com

https://bugs.python.org/issue33972

miss-islington pushed a commit that referenced this pull request

Jun 25, 2019

@maxking @miss-islington

…rror. (GH-14119) (GH-14381)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part. (cherry picked from commit 0225701)

Co-authored-by: Abhilash Raj maxking@users.noreply.github.com

https://bugs.python.org/issue33972

lisroach pushed a commit to lisroach/cpython that referenced this pull request

Sep 10, 2019

@maxking @lisroach

…ythonGH-14119)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.

DinoV pushed a commit to DinoV/cpython that referenced this pull request

Jan 14, 2020

@maxking @DinoV

…ythonGH-14119)

When certain malformed messages have content-type set to 'mulitpart/*' but still have a single part body, iter_attachments can raise AttributeError. This patch fixes it by returning a None value instead when the body is single part.

Labels

type-bug

An unexpected behavior, bug, or error