Feat: Add Configurable Discovery Validation Capabilities#37
Conversation
8b85d87 to
ab9865a
Compare
ab9865a to
922e121
Compare
|
Some preliminary comments for now. Will give it a proper review once a few other PRs settle. |
| timeout: float = 60.0, | ||
| poll_interval: float = 1.0, |
There was a problem hiding this comment.
Magic numbers: Can we make these named constants with units in base.py and share with validate_discovery_config?
| timeout: float = 60.0, | |
| poll_interval: float = 1.0, | |
| timeout_seconds: float = VALIDATION_TIMEOUT_SECONDS, | |
| poll_interval_seconds: float = VALIDATION_POLL_INTERVAL_SECONDS, |
| """Validation status; may be `in_progress` briefly after creating a large config.""" | ||
| validation_error: Optional[str] = Field(default=None, exclude=True) | ||
| """Human-readable validation error, or `None` when valid.""" | ||
| validation_error_details: list[ValidationErrorDetails] = Field(default_factory=list, exclude=True) |
There was a problem hiding this comment.
ruleset_library.py has a very similar looking field (of list[ValidationErrorDetails]) named validation_errors
Although I prefer validation_error_details since it aligns with the type, for consistency should we rename to match?
| validation_error_details: list[ValidationErrorDetails] = Field(default_factory=list, exclude=True) | |
| validation_errors: list[ValidationErrorDetails] = Field(default_factory=list, exclude=True) |
| def promote_error_locations(data: object) -> object: | ||
| """Flatten a server `errors` payload into a `validation_error_details` list.""" | ||
|
|
||
| if not isinstance(data, dict) or "errors" not in data: | ||
| return data | ||
| data = dict(data) | ||
| raw_errors = data.pop("errors") | ||
| entries: list[object] = [] | ||
| if isinstance(raw_errors, dict): | ||
| for value in raw_errors.values(): | ||
| if isinstance(value, list): | ||
| entries.extend(value) | ||
| elif isinstance(raw_errors, list): | ||
| entries = raw_errors | ||
| if entries: | ||
| data["validation_error_details"] = entries | ||
| return data |
There was a problem hiding this comment.
Could we declare the shape when defining validation_error_details and let pydantic do the parsing for us?
validation_error_details: list[ValidationErrorDetails] = Field(
default_factory=list,
exclude=True,
validation_alias=AliasChoices(AliasPath("errors", "config_yaml"), "validation_error_details"),
)(docs to pydantic aliasing) - Does this work?
| try: | ||
| delete() | ||
| except DataMasqueException: | ||
| logger.warning('Failed to clean up %s; remove it manually.', description) |
There was a problem hiding this comment.
The warning drops the underlying error, so finding the cause of it may be guesswork after it happens.
Suggestion: catch as e and include it in the message
Required for datamasque-cli PR.
Requires PR 36 being merged first or this branch merged into it.