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

Use strict API schemas #9365

Merged
merged 1 commit into from
Jun 18, 2020
Merged

Conversation

mik-laj
Copy link
Member

@mik-laj mik-laj commented Jun 18, 2020

The rules are already verified by connexion, but it's still worth forcing some unexpected errors to not be accidentally ignored.

    :param bool strict: If `True`, raise errors if invalid data are passed in
        instead of failing silently and storing the errors.

CC: @ephraimbuddy


Make sure to mark the boxes below before creating PR: [x]

  • Description above provides context of the change
  • Unit tests coverage for changes (not needed for documentation changes)
  • Target Github ISSUE in description if exists
  • Commits follow "How to write a good git commit message"
  • Relevant documentation is updated including usage instructions.
  • I will engage committers as explained in Contribution Workflow Example.

In case of fundamental code change, Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in UPDATING.md.
Read the Pull Request Guidelines for more information.

@boring-cyborg boring-cyborg bot added the area:API Airflow's REST/HTTP API label Jun 18, 2020
@ephraimbuddy
Copy link
Contributor

Nice!

@ephraimbuddy
Copy link
Contributor

I also suggest we enable strict validation here: airflow/www/extensions/init_views.py. It's currently disabled

specification='v1.yaml', base_path='/api/v1', validate_responses=True, strict_validation=False

@mik-laj
Copy link
Member Author

mik-laj commented Jun 18, 2020

@ephraimbuddy Good point. I will do.

Copy link
Member

@kaxil kaxil left a comment

Choose a reason for hiding this comment

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

@mik-laj
Copy link
Member Author

mik-laj commented Jun 18, 2020

@kaxil No. This has only changed in 3.0. We use marshmallow 2.*.
https://marshmallow.readthedocs.io/en/stable/upgrading.html#schemas-are-always-strict
However, we will want to migrate to the new version soon.
dpgaspar/Flask-AppBuilder#1382

@kaxil
Copy link
Member

kaxil commented Jun 18, 2020

How about using something like since we would always want the strict=True:

class Schema(marshmallow.Schema):
    def __init__(self, strict=True, **kwargs):
        super().__init__(strict=strict, **kwargs)

@mik-laj
Copy link
Member Author

mik-laj commented Jun 18, 2020

@kaxil This will complicate reviews because we will have to check imports. I do not see the problem that the code is repeated, because it is only one option.

Explicit is better than implicit.

https://www.python.org/dev/peps/pep-0020/

@ephraimbuddy
Copy link
Contributor

Some Schemas uses SQLALchemySchema from marshmallow_sqlalchemy

@kaxil
Copy link
Member

kaxil commented Jun 18, 2020

@kaxil This will complicate reviews because we will have to check imports. I do not see the problem that the code is repeated, because it is only one option.

Explicit is better than implicit.

https://www.python.org/dev/peps/pep-0020/

We will have to remove all the class that inherits then :D We can call it StrictSchema etc to be explicit.

Then main reason I recommended that was to enforce that we always use strict as it is easy to forget that in new PR and then we end up with some of them strict and some of them not. It is easy then to add pre-commit hook to check that only StrictSchema is used.

Anyways @ephraimbuddy makes a good point that we use SQLALchemySchema at some places. So let's keep it as it is. ✅

@mik-laj mik-laj merged commit 880b65a into apache:master Jun 18, 2020
@mik-laj mik-laj deleted the strict-schemaa branch June 18, 2020 12:14
kaxil pushed a commit to kaxil/airflow that referenced this pull request Jun 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:API Airflow's REST/HTTP API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants