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

fix: 🩹 update verify_properties_are_well_formed() based on changes to the Properties classes #832

Conversation

signekb
Copy link
Member

@signekb signekb commented Nov 1, 2024

Description

NB this is a stacked PR merging to #808

This PR changes the behaviour of verify_properties_are_wellformed() based on the changes to the Properties classes in #808

This work was done in collaboration with @martonvago 🌷 It's not pretty, but it gets the work done for now.
During this, we talked about #830 and how we think not using frictionless-py could simplify the work here as well, since the validate()function keeps surprising us by not working as we expect it to.

This PR needs an in-depth review.

Checklist

  • Added or updated tests
  • Tests passed locally
  • Linted and formatted code

@signekb signekb requested a review from a team as a code owner November 1, 2024 15:28

errors = [
error
for error in report.errors
+ [error for task in report.tasks for error in task.errors]
if error.type == error_type
if "required" not in error.message and error.type == error_type
Copy link
Member Author

Choose a reason for hiding this comment

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

This workaround, for example, is very non-ideal.

  1. To filter the required field errors, we have to go into the error message
  2. We have to filter on error type twice (here and on L28) to ensure we only catch the errors we intend to (either PackageError or ResourceError)

@@ -24,14 +25,17 @@ def verify_properties_are_well_formed(properties: dict, error_type: str) -> dict
non_empty_properties = {
key: value for key, value in properties.items() if value != ""
}
report = validate(non_empty_properties)
report = validate(non_empty_properties, type=error_type.replace("-error", ""))
Copy link
Member Author

Choose a reason for hiding this comment

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

Also not pretty 🥀

]

if properties == {}:
errors = [Error(note="Empty properties provided")]
Copy link
Member Author

Choose a reason for hiding this comment

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

We use Error as a general error type instead of PackageError and ResourceError respectively.

@signekb signekb changed the title feat: ✨ update verify_properties_are_well_formed() based on changes to the Properties classes fix: 🩹 update verify_properties_are_well_formed() based on changes to the Properties classes Nov 1, 2024
Copy link
Contributor

@martonvago martonvago left a comment

Choose a reason for hiding this comment

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

Thanks!! Approving but agreeing with all your comments

Copy link
Member

@lwjohnst86 lwjohnst86 left a comment

Choose a reason for hiding this comment

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

Yea, agreed. Too bad about frictionless's validate() 😒

@lwjohnst86 lwjohnst86 merged commit 933e069 into fix/avoid-overwriting-non-edited-properties Nov 3, 2024
2 checks passed
@lwjohnst86 lwjohnst86 deleted the fix/update-verify_properties_are_well_formed-based-on-properties branch November 3, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants