Repository navigation
fix(declarative): surface failing path and constraint in manifest validation errors #1170
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
Draft
devin-ai-integration
wants to merge
2
commits into
main
Choose a base branch
from
devin/1790057279-manifest-validation-error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,7 +56,9 @@ def safe_build_source( | |
| slice_limit, | ||
| ) | ||
| except jsonschema.exceptions.ValidationError as e: | ||
| raise HTTPException(status_code=400, detail=f"Invalid manifest: {e.message}") | ||
| raise HTTPException( | ||
| status_code=400, detail=filter_secrets(f"Invalid manifest: {e.message}") | ||
| ) | ||
|
|
||
|
|
||
| router = APIRouter( | ||
|
|
@@ -213,6 +215,9 @@ def resolve(request: ResolveRequest) -> ManifestResponse: | |
| try: | ||
| source = safe_build_source(request.manifest.model_dump(), {}) | ||
| return ManifestResponse(manifest=Manifest(**source.resolved_manifest)) | ||
| except HTTPException: | ||
| # Re-raise HTTPExceptions as-is (like the invalid manifest check in safe_build_source) | ||
| raise | ||
| except Exception as exc: | ||
| # Filter secrets from error message before returning to client | ||
| sanitized_message = filter_secrets(f"Error resolving manifest: {str(exc)}") | ||
|
|
@@ -258,6 +263,9 @@ def full_resolve(request: FullResolveRequest) -> ManifestResponse: | |
|
|
||
| manifest["streams"] = streams | ||
| return ManifestResponse(manifest=Manifest(**manifest)) | ||
| except HTTPException: | ||
| # Re-raise HTTPExceptions as-is (like the invalid manifest check in safe_build_source) | ||
| raise | ||
|
Comment on lines
+266
to
+268
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. βοΈ Resolved in ba9e995. Same fix as |
||
| except Exception as exc: | ||
| # Filter secrets from error message before returning to client | ||
| sanitized_message = filter_secrets(f"Error full resolving manifest: {str(exc)}") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
airbyte_cdk/sources/declarative/manifest_validation_error.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| # | ||
| # Copyright (c) 2025 Airbyte, Inc., all rights reserved. | ||
| # | ||
|
|
||
| from collections import defaultdict | ||
| from typing import Any, Dict, List, Optional, Sequence, Tuple, Union | ||
|
|
||
| from jsonschema.exceptions import ValidationError | ||
|
|
||
| _MAX_VALUE_REPR_LENGTH = 100 | ||
| _ROOT_PATH = "<root>" | ||
|
|
||
|
|
||
| def format_manifest_validation_error(error: ValidationError) -> str: | ||
| """Builds a user-facing message naming the failing manifest field and the violated constraint. | ||
|
|
||
| `error` is expected to be the error raised by `jsonschema.validate`, i.e. the result of | ||
| `jsonschema.exceptions.best_match`. For `anyOf`/`oneOf` errors, the sub-errors of the branches | ||
| are merged so that e.g. a wrong `type` discriminator reports every allowed value instead of | ||
| the opaque "is not valid under any of the given schemas". | ||
| """ | ||
| path, constraint = _describe(error) | ||
| return f"Manifest field '{path}' is invalid: {constraint}." | ||
|
|
||
|
|
||
| def _describe(error: ValidationError) -> Tuple[str, str]: | ||
| base_path: List[Union[str, int]] = list(error.absolute_path) | ||
| if error.validator in ("anyOf", "oneOf") and error.context: | ||
| merged = _merge_branch_errors(error, base_path) | ||
| if merged: | ||
| return merged | ||
| return ( | ||
| _format_path(base_path), | ||
| "the value does not match any of the allowed component definitions", | ||
| ) | ||
| return _format_path(base_path), _describe_single(error) | ||
|
|
||
|
|
||
| def _merge_branch_errors( | ||
| error: ValidationError, base_path: List[Union[str, int]] | ||
| ) -> Optional[Tuple[str, str]]: | ||
| by_path: Dict[Tuple[Union[str, int], ...], List[ValidationError]] = defaultdict(list) | ||
| for sub_error in error.context: | ||
| by_path[tuple(sub_error.relative_path)].append(sub_error) | ||
| shallowest = min(by_path, key=len) | ||
| candidates = by_path[shallowest] | ||
| validators = {sub_error.validator for sub_error in candidates} | ||
| if validators == {"enum"}: | ||
| allowed: List[Any] = [] | ||
| for sub_error in candidates: | ||
| for value in sub_error.validator_value: | ||
| if value not in allowed: | ||
| allowed.append(value) | ||
| return ( | ||
| _format_path(base_path + list(shallowest)), | ||
| f"value {_short_repr(candidates[0].instance)} is not one of {_format_options(allowed)}", | ||
| ) | ||
| if validators == {"required"}: | ||
| present = candidates[0].instance if isinstance(candidates[0].instance, dict) else {} | ||
| missing: List[str] = [] | ||
| for sub_error in candidates: | ||
| for prop in sub_error.validator_value: | ||
| if prop not in present and prop not in missing: | ||
| missing.append(prop) | ||
| return ( | ||
| _format_path(base_path + list(shallowest)), | ||
| f"one of the following properties is required: {', '.join(repr(prop) for prop in missing)}", | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| def _describe_single(error: ValidationError) -> str: | ||
| if error.validator == "enum": | ||
| return f"value {_short_repr(error.instance)} is not one of {_format_options(error.validator_value)}" | ||
| if error.validator == "type": | ||
| expected = error.validator_value | ||
| expected_str = ( | ||
| " or ".join(f"'{t}'" for t in expected) | ||
| if isinstance(expected, list) | ||
| else f"'{expected}'" | ||
| ) | ||
| return f"value {_short_repr(error.instance)} is not of type {expected_str}" | ||
| return str(error.message) | ||
|
|
||
|
|
||
| def _format_path(path: Sequence[Union[str, int]]) -> str: | ||
| if not path: | ||
| return _ROOT_PATH | ||
| formatted = "" | ||
| for part in path: | ||
| if isinstance(part, int): | ||
| formatted += f"[{part}]" | ||
| else: | ||
| formatted += f".{part}" if formatted else str(part) | ||
| return formatted | ||
|
|
||
|
|
||
| def _format_options(options: Sequence[Any]) -> str: | ||
| return "[" + ", ".join(repr(option) for option in options) + "]" | ||
|
|
||
|
|
||
| def _short_repr(value: Any) -> str: | ||
| text = repr(value) | ||
| if len(text) > _MAX_VALUE_REPR_LENGTH: | ||
| return text[: _MAX_VALUE_REPR_LENGTH - 3] + "..." | ||
| return text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
βοΈ Resolved in ba9e995. Valid concern β the new message includes
repr(value). Rather than re-wrapping in each route,safe_build_sourcenow appliesfilter_secretsto theInvalid manifest: ...detail itself, so every caller (including the re-raised path inresolve/full_resolve) is sanitized. Addedtest_safe_build_source_filters_secrets_from_validation_error.Devin session