Skip to content

Fix validation in directives and devices - #329

Merged
jdhall75 merged 5 commits into
thatmattlove:mainfrom
Computroniks:computroniks/bug/#311-fix-field-validation
Sep 28, 2025
Merged

jdhall75 merged 5 commits into
thatmattlove:mainfrom
Computroniks:computroniks/bug/#311-fix-field-validation

Conversation

@Computroniks

@Computroniks Computroniks commented Jun 4, 2025 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes multiple validation related issues

  1. Some of the field validator methods for device config used values as a dictionary (presumably from an old version of pydantic). This is now passed as a ValidationInfo object by pydantic, which caused issues when code attempted to access it. The affected methods have been updated to fix the issue.
  2. Previously, when processing rules with no condition, an extra RuleWithPattern rule was also added to the rule list causing a validation error. This behaviour has been prevented meaning only a RuleWithoutValidation rule is added.
  3. Update docs so they include required options for field in the examples.
  4. Fixed API docs rendering. The use of strip_whitespace in Field for the query validation model caused the automatic generation of the API docs to fail with ValueError: schema_extradeclares keystrip_whitespacewhich does not exist inSchema object. By switching from Field to Annotated with StringConstraints, this avoids this issue allowing API docs to be correctly rendered.

Related Issues

Fix #311

Motivation and Context

I am currently deploying hyperglass and have run into a few issues with config validation and I am fixing them as I encounter them.

Previously hyperglass would crash when starting with various configurations.

Tests

Manual testing of fixes before and after to ensure issues do not persist after change.

Some of the field validator methods for device config used `values` as a dictionary (presumably from an old version of pydantic). This is now passed as a `ValidationInfo` object by pydantic, which caused issues when code attempted to access it. The affected methods have been updated to fix the issue.

Fix thatmattlove#311

Signed-off-by: Mattie Nickson <mnickson@sidingsmedia.com>
Previously, when processing rules with no condition, an extra RuleWithPattern rule was also added to the rule list causing a validation error. This has been corrected.

Signed-off-by: Mattie Nickson <mnickson@sidingsmedia.com>
@Computroniks Computroniks changed the title Fix #311: Field validation for device config Fix validation in directives and devices Jun 4, 2025
Signed-off-by: Mattie Nickson <mnickson@sidingsmedia.com>
@Computroniks
Computroniks force-pushed the computroniks/bug/#311-fix-field-validation branch from ca3c542 to f49ff54 Compare June 4, 2025 17:35
The use of `strip_whitespace` in `Field` for the query validation model caused the automatic generation of the API docs to fail with `ValueError: `schema_extra` declares key `strip_whitespace` which does not exist in `Schema` object`. By switching from `Field` to `Annotated` with `StringConstraints`, this avoids this issue allowing API docs to be correctly rendered.

Signed-off-by: Mattie Nickson <mnickson@sidingsmedia.com>
@jdhall75
jdhall75 merged commit 43d3c66 into thatmattlove:main Sep 28, 2025
8 checks passed
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.

Avatar Error

2 participants