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

Feature/strict schema #169

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Sytten
Copy link

@Sytten Sytten commented Feb 8, 2020

Fixes #161
This adds a new StrictSchema which we should recommend for new users in #152. It's a simple combination of RequestSchema and ResponseSchema. This is also interesting if we want to extend some functionality of marshmallow down the road.

I also added a simple constructor to ResponseSchema because of #137. A future improvement (if/when we drop marshmallow v2) would be to have all the keyword arguments so the IDE can pick it up and suggest them to the user. At least now it doesn't show up as an error.

@Sytten Sytten requested a review from a team as a code owner February 8, 2020 04:23
@ghost ghost assigned airstandley Feb 8, 2020
class ResponseSchema(ActuallyRequireOnDumpMixin, Schema):
def __init__(self, **kwargs):
super().__init__(**kwargs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Function call overhead in python is significant. It’s best practice not to introduce this extra no-op function call that reduces performance just for some IDEs that aren’t currently finding the inherited method. Can you follow up with your IDE vendor instead of adding this here?

super().__init__(**kwargs)


class StrictSchema(RequestSchema, ResponseSchema):
pass
Copy link
Collaborator

Choose a reason for hiding this comment

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

Missing docstring for public class.

Once added, the pass will be unnecessary.

@@ -117,6 +117,30 @@ def test_required_failed_validate(self):
self.assertIn("one_of_validation", ctx.exception.messages)


class ActuallyStrictSchema(StrictSchema):
Copy link
Collaborator

Choose a reason for hiding this comment

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

TestStrictSchema or MyStrictSchema? Shout out to #170.

super().__init__(**kwargs)


class StrictSchema(RequestSchema, ResponseSchema):
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • Better to inherit the mixin classes directly
  • I wonder if there’s a better name than StrictSchema for this, since strict is overloaded with other meaning in Marshmallow v2 (complicated by how Rebar currently already always does a strict load with unstrict Marshmallow v2 schemas, i.e. raising rather than returning a value with errors in it)

@jab
Copy link
Collaborator

jab commented Feb 8, 2020

  • should we deprecate Request and ResponseSchema at the same time?
  • docs and changelog?

@Sytten
Copy link
Author

Sytten commented Feb 8, 2020

  • no we have some use cases for them as an advanced feature
  • true my bad

@airstandley airstandley added the enhancement New feature or request label Feb 13, 2020
@airstandley
Copy link
Contributor

@Sytten Thanks for working on this. It looks great, but I would echo the comments about wanting the no-op init removed and documentation updates being needed.

@gtmanfred
Copy link
Contributor

Looks like we have some merge conflicts with this pr. I am working on cleaning up the backlog for flask rebar, so if i can help, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor RequestSchema and ResponseSchema into a single Schema
4 participants