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

Error-checking in Mail helper/ASM #413

Merged
merged 8 commits into from
Oct 30, 2017

Conversation

gabrielkrell
Copy link
Contributor

@gabrielkrell gabrielkrell commented Oct 23, 2017

Among other things, API docs say that if the asm field is provided, group_id is required and groups_to_display is limited to 25 groups. Change Mail helper's ASM class so that it (a) requires a group_id and (b) raises an exception if more than 25 groups to display are provided.

There are some other limits that the API specifies, but I guess they'll go in separate PRs since I probably won't finish them within the next few days.

If the optional ASM is specified, the API says the group_id is mandatory.
API says "You can specify up to 25 groups to display."  If param is too long, raise ValueError.
@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Oct 23, 2017
@codecov-io
Copy link

codecov-io commented Oct 23, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@f1933ff). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #413   +/-   ##
=========================================
  Coverage          ?   83.36%           
=========================================
  Files             ?       30           
  Lines             ?     1022           
  Branches          ?      159           
=========================================
  Hits              ?      852           
  Misses            ?       82           
  Partials          ?       88
Impacted Files Coverage Δ
sendgrid/helpers/mail/asm.py 90.47% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f1933ff...02576b3. Read the comment docs.

Do we really need this?  It makes Codecov happy though.
@gabrielkrell
Copy link
Contributor Author

gabrielkrell commented Oct 23, 2017

Oops, just saw the header "The following objects are meant to be extended with validation". 🤦 If that's still true you can close this. Otherwise I'll add some more elsewhere in the helper.

Copy link
Contributor

@mbernier mbernier left a comment

Choose a reason for hiding this comment

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

This looks good, I added a couple comments to see what you think.

Thanks, @gabrielkrell!!


if groups_to_display is not None:
self._groups_to_display = groups_to_display
def __init__(self, group_id, groups_to_display=None):
Copy link
Contributor

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 changing L710 to be

self.groups_to_display = groups_to_display

and then moving the validation and exception to line 724 ?

I think that this would allow any setting of the groups to be handled in the same way, whether by init or otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add logic to group_id that causes a similar exception if it is turned on and there are more than 25 groups?

Copy link
Contributor Author

@gabrielkrell gabrielkrell Oct 28, 2017

Choose a reason for hiding this comment

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

You're right; I'll put that in the property.

If you're OK with doing error-checking in Mail I'll do that and look for other API limits that we can verify. I think there are a few character limits somewhere.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that it makes sense to try to catch the limitations in the natural and earliest bottlenecks. That way, the code fails quickly, rather than after running all the way through and then failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I mean like in the Mail helper and the small classes (e.g. Personalization), not just the Mail class. I saw that big comment about leaving validation up to the user so I wanted to make sure it was OK to do it ourselves here.

Copy link
Contributor

@mbernier mbernier left a comment

Choose a reason for hiding this comment

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

Hey @gabrielkrell can you double check the merge conflicts? It looks like #472 may have conflicts with your work here.

@gabrielkrell
Copy link
Contributor Author

@mbernier Sure thing (please wait to merge though until I add some more error checking stuff; I'll ping you). I'll update #438 as well.

@mbernier
Copy link
Contributor

@gabrielkrell I just saw your reply ^
I will hang out.
Thanks!

@gabrielkrell gabrielkrell changed the title Error-checking in Mail helper/ASM Error-checking in Mail helper Oct 29, 2017
@mbernier
Copy link
Contributor

@gabrielkrell are we good to go? (Don't worry about the codeclimate report right now)

@gabrielkrell gabrielkrell changed the title Error-checking in Mail helper Error-checking in Mail helper/ASM Oct 30, 2017
@gabrielkrell
Copy link
Contributor Author

Yeah I think this is ready. It'll stay a small PR for now; I haven't had time to put in checks for other API limits.

@mbernier mbernier merged commit 7c5bf33 into sendgrid:master Oct 30, 2017
@thinkingserious
Copy link
Contributor

Hello @gabrielkrell,

Thanks again for the PR!

It's HACKTOBERFEST! We want to show our appreciation by sending you some special Hacktoberfest swag. If you have not already, could you please fill out this form so we can send it to you? Thanks!

Team SendGrid DX

@thinkingserious thinkingserious added the difficulty: medium fix is medium in difficulty label Nov 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty: medium fix is medium in difficulty status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants