Skip to content
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

6.0.2 fails to send to list of lists #778

Closed
plowman opened this issue Apr 3, 2019 · 4 comments · Fixed by #920
Closed

6.0.2 fails to send to list of lists #778

plowman opened this issue Apr 3, 2019 · 4 comments · Fixed by #920
Labels
difficulty: easy fix is easy in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap

Comments

@plowman
Copy link

plowman commented Apr 3, 2019

Issue Summary

Something I ran into while upgrading to 6.0.2 just now is that when sending a Mail object with a to_emails= parameter that is a list of [[email, name]], a confusing exception is thrown while if it's a list of [(email, name)], it succeeds.

This snippet fails

from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail

email_list = [["[email protected]", "Benjamin Uno"],
              ["[email protected]", "Benjamin Dos"]]
mail = Mail(subject=subject,
            html_content=content,
            from_email=("[email protected]", "Website Team"),
            to_emails=email_list,
            )
sendgrid_client = SendGridAPIClient('abcd123')
sendgrid_client.send(mail)

The exception thrown is ValueError: Please use a To, Cc or Bcc object.

This snippet succeeds

email_list = [("[email protected]", "Benjamin Uno"),
              ("[email protected]", "Benjamin Dos")]

# (( Same code as above ))

Steps to Reproduce

  1. Run the initial snippet above

Expected

  • Option 1: accept a list of lists as well as a list of tuples. This seems doable but there may be ancient backwards incompatibility reasons why it's hard.
  • Option 2: fail immediately if you see a list of lists. Otherwise the error "Please use a To, Cc or Bcc object." is pretty confusing and took me a while to figure out why sendgrid was unhappy.

Technical details:

  • sendgrid-python Version: 6.0.2
  • Python Version: 3.7
@thinkingserious
Copy link
Contributor

thinkingserious commented Apr 3, 2019

Hi @plowman!

Thanks for reporting this! Yes, that error is confusing in this context and I'll leave this open for a fix.

to_emails currently requires either a list of Email/To/Cc/Bcc objects or a list of tuples. I did not think to include the ability of allowing a list of lists.

Would a better error do the trick or are you also wanting to be able to pass a list of lists?

With Best Regards,

Elmer

@thinkingserious thinkingserious added difficulty: unknown or n/a fix is unknown in difficulty status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Apr 3, 2019
@plowman
Copy link
Author

plowman commented Apr 3, 2019

Hey @thinkingserious thanks for the fast reply! I don't have a strong preference on the fix. Throwing an error when I call send() with a list of lists would probably do the trick.

@thinkingserious thinkingserious added difficulty: easy fix is easy in difficulty help wanted status: help wanted requesting help from the community and removed difficulty: unknown or n/a fix is unknown in difficulty status: waiting for feedback waiting for feedback from the submitter type: question question directed at the library labels Apr 3, 2019
@helle253
Copy link

Is this still available? I have a couple of follow-up questions that are a bit beyond the scope of this issue, but may be worth taking a look at separately:

It looks like there may be some similar issues with parsing a list of dictionaries. Should this be fixed, too? Or is throwing a better error still an acceptable fix?

Similar parsing issues re:lists/dictionaries exist for adding BCC and CC parameters as well, but the Mail object doesn't take cc/bcc email parameters? What is the rationale for this?

Thanks :)

@childish-sambino childish-sambino added type: community enhancement feature request not on Twilio's roadmap and removed type: enhancement labels Apr 8, 2020
@DougCal
Copy link
Contributor

DougCal commented Jul 2, 2020

Going to look into this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: easy fix is easy in difficulty status: help wanted requesting help from the community type: community enhancement feature request not on Twilio's roadmap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants