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

Add checks for required parameters to Provider scripts (K-R) #1884

Merged
merged 5 commits into from
May 5, 2023

Conversation

obulat
Copy link
Contributor

@obulat obulat commented Apr 24, 2023

Fixes

Fixes #1883 by @obulat

Description

This PR replaces is None checks for required values with if <value> checks because falsy values such as empty string or empty list should also short-circuit the provider API scripts.

Testing Instructions

All the CI tests should pass.

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@obulat obulat requested a review from a team as a code owner April 24, 2023 06:07
@obulat obulat requested review from krysal and stacimc April 24, 2023 06:07
@obulat obulat added 🟩 priority: low Low priority and doesn't need to be rushed 💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🧱 stack: catalog Related to the catalog and Airflow DAGs labels Apr 24, 2023
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Nice! I'm surprised there were not more tests which were affected. Do you think it makes sense to go through and add test cases for the providers which check against a few falsy values?

@obulat obulat force-pushed the add/stricter_checks branch 4 times, most recently from 9f83a94 to cc606ca Compare April 25, 2023 06:47
@obulat obulat marked this pull request as draft April 25, 2023 12:35
@obulat obulat force-pushed the add/stricter_checks branch from df2a4b0 to 4b17bfe Compare April 26, 2023 04:37
@obulat obulat changed the title Replace is None checks with not checks Check that required media parameters are not falsy Apr 28, 2023
@obulat obulat force-pushed the add/stricter_checks branch from c4c5958 to d80d706 Compare April 28, 2023 13:42
@obulat obulat self-assigned this Apr 30, 2023
@obulat obulat force-pushed the add/stricter_checks branch from 3833b44 to d611eba Compare May 2, 2023 14:53
@obulat obulat changed the base branch from main to refactor/license_info May 2, 2023 14:53
@obulat obulat changed the title Check that required media parameters are not falsy Add checks for required parameters to Provider scripts (K-R) May 2, 2023
@obulat obulat force-pushed the add/stricter_checks branch from d611eba to f2697cb Compare May 2, 2023 16:06
@obulat obulat force-pushed the refactor/license_info branch from 9ce9453 to 6a749c9 Compare May 2, 2023 18:56
@obulat obulat force-pushed the add/stricter_checks branch from f2697cb to 629b1a8 Compare May 2, 2023 18:57
@obulat obulat force-pushed the refactor/license_info branch from 6a749c9 to 127781b Compare May 3, 2023 03:16
@obulat obulat force-pushed the add/stricter_checks branch from 629b1a8 to a882797 Compare May 3, 2023 03:17
Base automatically changed from refactor/license_info to main May 3, 2023 03:34
@obulat obulat force-pushed the add/stricter_checks branch from a882797 to 0c599b4 Compare May 3, 2023 03:51
@obulat obulat force-pushed the add/stricter_checks branch from efeff99 to 73041ec Compare May 4, 2023 11:57
@obulat obulat marked this pull request as ready for review May 4, 2023 11:57
@obulat obulat requested a review from AetherUnbound May 4, 2023 11:57
@obulat
Copy link
Contributor Author

obulat commented May 4, 2023

@AetherUnbound, I re-requested your review because this PR has changed a lot since your approval.

Copy link
Member

@krysal krysal left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for caring about splitting the changes for easier reviews and adding type hints ✨

Copy link
Collaborator

@stacimc stacimc left a comment

Choose a reason for hiding this comment

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

LGTM, no blocking requests. Thanks for all the additional cleanup and type hints added as well :)

media_data = media[size]
break
image_url = media_data.get("uri")
if image_url is not None:
if image_url := media_data.get("uri"):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could image_url still be falsy here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it shouldn't because we check that media[size].get("uri") is not falsy above (I updated the check).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless we didn't find any size in media, in which case media_data is still {}. So we still have to have the check.

title_info = mods.get("titleInfo")
if isinstance(title_info, list) and title_info:
title_info = title_info[0]
return "" if title_info is None else title_info.get("title", {}).get("$")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this is None check also be changed to a check for falsy values?

@obulat obulat merged commit 7fea347 into main May 5, 2023
@obulat obulat deleted the add/stricter_checks branch May 5, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository 🧰 goal: internal improvement Improvement that benefits maintainers, not users 🟩 priority: low Low priority and doesn't need to be rushed 🧱 stack: catalog Related to the catalog and Airflow DAGs
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Provider API value checks should filter out all falsy values, not only None
4 participants