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

Validate config min/max values #474

Merged
merged 1 commit into from
Mar 6, 2023

Conversation

JosephMarinier
Copy link
Contributor

@JosephMarinier JosephMarinier commented Mar 2, 2023

Description:

Very simple and repetitive PR about validating the min and max values to the number fields in the config.

Checklist:

You should check all boxes before the PR is ready. If a box does not apply, check it to acknowledge it.

  • ISSUE NUMBER. You linked the issue number (Ex: Resolve #XXX).
  • PRE-COMMIT. You ran pre-commit on all commits, or else, you
    ran pre-commit run --all-files at the end.
  • USER CHANGES. The changes are added to CHANGELOG.md and the documentation, if they impact
    our users.
  • DEV CHANGES.
    • Update the documentation if this PR changes how to develop/launch on the app.
    • Update the README files and our wiki for any big design decisions, if relevant.
    • Add unit tests, docstrings, typing and comments for complex sections.

@JosephMarinier JosephMarinier self-assigned this Mar 2, 2023
syntax.spacy_model = syntax.spacy_model or defaults.spacy_model
syntax.subj_tags = syntax.subj_tags or defaults.subj_tags
syntax.obj_tags = syntax.obj_tags or defaults.obj_tags
if similarity := values.get("similarity"):
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 changed values["similarity"] to values.get("similarity") (as well as the others) because the individual fields get validated by Pydantic first, before calling this @root_validator(). If Pydantic raises a ValidationError while validating similarity (like if no_close_threshold is outside the min/max range), it caries on with the rest of the validation to get an exhaustive list of validation errors, so we end up here with similarity that doesn't exist. In this context, values["similarity"] was producing a no-helpful KeyError (and not a ValidationError) that was "hiding" the validation error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the explanation!

@JosephMarinier JosephMarinier marked this pull request as ready for review March 2, 2023 22:58
Copy link
Contributor

@gabegma gabegma left a comment

Choose a reason for hiding this comment

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

LGTM!

syntax.obj_tags = syntax.obj_tags or defaults.obj_tags
if values["similarity"]:
similarity = values["similarity"]
if syntax := values.get("syntax"):
Copy link
Contributor

Choose a reason for hiding this comment

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

Even though syntax is never optional at the moment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, for the reason I gave here.

Copy link
Contributor

@gabegma gabegma Mar 3, 2023

Choose a reason for hiding this comment

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

Ah ok. if I rephrase, do you mean that if there is a problem with one syntax field (like the value being out of bound), the syntax options will be set to None or something like that, which will then break the old line 418, hiding the original error with the syntax field? If so, can we think of some comments to add so we don't forget? Or is basically your test testing that we have the appropriate error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, "hiding the original error" with a KeyError on old line 418.
My test ensures that we get the expected ValidationError, which is the only type of exception pydantic is supposed to return. A KeyError makes the test fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, I get it now :)

no_close_threshold: float = 0.5
faiss_encoder: str = Field("", description="Language-based dynamic default value.")
conflicting_neighbors_threshold: float = Field(
0.9, ge=0, le=1, description="Threshold to use when finding conflicting neighbors."
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea to convert comments into descriptions!

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 we should do it throughout maybe? But it can be in a future PR.

@JosephMarinier JosephMarinier force-pushed the joseph/validate-config-min-max-values branch 2 times, most recently from 7ad8b87 to 7eb79be Compare March 6, 2023 16:38
@JosephMarinier JosephMarinier merged commit b8d3bff into main Mar 6, 2023
@JosephMarinier JosephMarinier deleted the joseph/validate-config-min-max-values branch March 6, 2023 17:24
JosephMarinier added a commit that referenced this pull request Mar 6, 2023
…oad-config-history

* commit '674585e9bdfd543771ee74b407059b41fc979f24':
  Clean up docker image (#316)
  Validate config min/max values (#474)
  Bump werkzeug from 2.1.0 to 2.2.3 (#443)
  Bump dns-packet from 5.3.1 to 5.4.0 in /webapp (#473)
  Update tensorflow (#355)
  Bump json5 from 1.0.1 to 1.0.2 in /webapp (#359)
  Fix negative query params (#471)
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.

2 participants