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

Enforcedefaults aiohttp #1163

Merged
merged 3 commits into from
Feb 23, 2022
Merged

Conversation

p4l1ly
Copy link
Contributor

@p4l1ly p4l1ly commented Feb 20, 2020

Fixes #1162 .

Changes proposed in this pull request:

  • Lazy load the ConnexionRequest.json property.
  • Example added.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 96.294% when pulling fd6174d on p4l1ly:enforcedefaults_aiohttp into 96bdcb0 on zalando:master.

@@ -24,7 +23,9 @@ def __init__(self,

@property
def json(self):
return self.json_getter()
if not hasattr(self, '_json'):
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 this change is unrelated to your example, why did you add it?

Copy link
Contributor Author

@p4l1ly p4l1ly Feb 21, 2020

Choose a reason for hiding this comment

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

It is related. Actually, it fixes the issue #1162. As opposed to FlaskApp, this code says that the body is recomputed each time we access ConnexionRequest.json. So if a validator changes the json, it is not reflected in the body argument because here it is recomputed again. This change avoids the recomputation and uses the same reference (which has been modified by the validator) again.

Copy link
Contributor Author

@p4l1ly p4l1ly Feb 21, 2020

Choose a reason for hiding this comment

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

Really, please try the example without this change and see that it behaves differently (the foo attribute is not added with the default value).

@RobbeSneyders RobbeSneyders changed the base branch from master to main February 23, 2022 21:26
@coveralls
Copy link

Pull Request Test Coverage Report for Build 1889774255

  • 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 96.747%

Totals Coverage Status
Change from base Build 1883321425: 0.002%
Covered Lines: 2885
Relevant Lines: 2982

💛 - Coveralls

Copy link
Member

@RobbeSneyders RobbeSneyders left a comment

Choose a reason for hiding this comment

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

Thx @p4l1ly!

@RobbeSneyders RobbeSneyders merged commit a6717c3 into spec-first:main Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Body validator cannot change body itself when using AioHttpApp
4 participants