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

[Controller] Introduces Rules For Kwargs Checking #57

Merged
merged 2 commits into from
Jul 12, 2021

Conversation

Rubix982
Copy link
Contributor

Introduced "rules" for controller/, helps to implement DRY for various requirements and be a single point of failure given wrong keyword arguments are passed.

Compliments #56

…s requirements and be a single point of failure given wrong kwargs are passed
@Rubix982 Rubix982 added the controller Regarding controllers label Jul 12, 2021
@Rubix982 Rubix982 self-assigned this Jul 12, 2021
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 12, 2021
@Rubix982
Copy link
Contributor Author

@OmarMuhammedAli I implemented the thumbnail_size_check before I saw your exception class - maybe we can refactor it in a new PR?

@OmarMuhammedAli
Copy link
Contributor

@Rubix982 Yep! let's do that

Comment on lines +29 to +37
if ("min_date" in kwargs or "max_date" in kwargs) and ("daterange" in kwargs):

# Check if two contradicting keys have not been given
raise ContradictingError(
contradicts="daterange",
contradicted="min_date/max_date",
message="Using either or both of min_date and max_date, or use daterange, "
"but not both at the same time",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain what this snippet does? what constitutes contradiction between different kwargs?

Copy link
Contributor Author

@Rubix982 Rubix982 Jul 12, 2021

Choose a reason for hiding this comment

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

In the case of the example here, if the user decides to give the date in the format of a list for the key date range, and then also pass in max_date, and min_date, it becomes confusing about what the user actually wants to filter through - the provided list or the individually given arguments.

In the case where we remove daterange altogether, this wouldn't need to be here.

Given that context, this code snippet throws a ContradictingError when both the kwargs are provided.

@cbeddow should we remove daterange all together, and just keep a min_date and a max_date argument?

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 having either min_date and max_date or daterange as a chronological filtering mechanism will be sufficient, having both is redundant imo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. If a user can turn the dates into a list to pass to date range, they can just pass to max_date, and min_date as well, but I'll wait over what @cbeddow has to say about it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, remove daterange, this seems to be the same end, a range from min_date to max_date

Copy link
Contributor

@OmarMuhammedAli OmarMuhammedAli left a comment

Choose a reason for hiding this comment

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

Good work!
Would suggest clarifying the kwargs, what they are for each check, what are they based on, and how they may contradict one another

@Rubix982
Copy link
Contributor Author

Good work!
Would suggest clarifying the kwargs, what they are for each check, what are they based on, and how they may contradict one another

Thanks!

For the "what they are for each check, what are they based on" suggestion, what should I add? Will the explanation in the DocStrings of controllers/ be enough? How can I clarify the kwargs more?

Committing suggestions as per review

Co-authored-by: Omar Ali <omarmuhammed1998.om@gmail.com>
@OmarMuhammedAli
Copy link
Contributor

OmarMuhammedAli commented Jul 12, 2021

Thanks!

For the "what they are for each check, what are they based on" suggestion, what should I add? Will the explanation in the DocStrings of controllers/ be enough? How can I clarify the kwargs more?

Oh I've just seen the explanations in controller/. They're more than enough 😄

@Rubix982
Copy link
Contributor Author

@OmarMuhammedAli okieeesss.

Should I self-merge, or you?

@OmarMuhammedAli OmarMuhammedAli merged commit edb6518 into main Jul 12, 2021
@OmarMuhammedAli
Copy link
Contributor

Just merged!

@OmarMuhammedAli OmarMuhammedAli deleted the Rules-For-Controller branch July 12, 2021 20:14
@Rubix982
Copy link
Contributor Author

Ly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. controller Regarding controllers
Projects
MLH Fellowship
Awaiting triage
Development

Successfully merging this pull request may close these issues.

None yet

4 participants