Repository navigation
fix(low-code): interpolate PredicateValidator.value and allow plain strings in ValidateAdheresToSchema - #1210
Draft
devin-ai-integration[bot] wants to merge 1 commit into
Draft
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
…d validate plain strings in ValidateAdheresToSchema Co-Authored-By: bot_apk <apk@cognition.ai>
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
👋 Greetings, Airbyte Team Member!Here are some helpful tips and reminders for your convenience. 💡 Show Tips and TricksTesting This CDK VersionYou can test this version of the CDK using the following: # Run the CLI from this branch:
uvx 'git+https://github.com/airbytehq/airbyte-python-cdk.git@devin/1791298421-fix-predicate-validator#egg=airbyte-python-cdk[dev]' --help
# Update a connector to use the CDK from this branch ref:
cd airbyte-integrations/connectors/source-example
poe use-cdk-branch devin/1791298421-fix-predicate-validatorPR Slash CommandsAirbyte Maintainers can execute the following slash commands on your PR:
|
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
👉 TL;DR: Makes the declarative config validators actually usable: a predicate check can now compute its value from the user's config, and a schema check can validate a plain text value such as a hostname.
Specifically,
PredicateValidatornow implementsValidator.validate(input_data)and interpolatesvalueagainst the config passed bySpec.validate_config, andValidateAdheresToSchemafalls back to validating the raw string when astrvalue is not JSON.Resolves https://github.com/airbytehq/airbyte-internal-issues/issues/17719:
Close on merge: yes — internally filed, no customer to confirm with.
Parent epic: https://github.com/airbytehq/airbyte-internal-issues/issues/17702 (adopter migrations for
source-amazon-seller-partnerandsource-jiraare tracked separately and are not part of this PR).Changes
PredicateValidator(validators/predicate_validator.py)Validatorand accepts the config:validate(self, input_data: Optional[Mapping] = None). Previouslyvalidate(self)took no argument, soSpec.validate_config->validator.validate(config)raisedTypeError: PredicateValidator.validate() takes 1 positional argument but 2 were givenfor any manifest using it underconfig_normalization_rules.validations.valueis interpolated withJinjaInterpolation.eval(value, config)at validate time (string leaves, recursing into lists and object values; non-string literals pass through unchanged). BecauseSpecruns config transformations before validations, values can read keys added byConfigAddFields.JinjaInterpolationliteral-parses the rendered output, so"{{ config['report_options_list'] | map(attribute='stream_name') | list }}"reaches the strategy as alist, not"['a', 'b']".validate()with no argument still works (interpolates against{}), keeping the existing unit tests unchanged.ValidateAdheresToSchema.validate: astrvalue is still JSON-decoded first; onJSONDecodeErrorthe raw string is validated instead of raisingValueError("Invalid JSON string: ..."). This makesDpathValidator(field_path=["domain"]) + {type: string, pattern: ...}work. Failures are still raised asValueError.PredicateValidator.valuedescription and examples updated (adds themap(attribute=...) | listexample). No structural schema change;ModelToComponentFactory.create_predicate_validatoris unchanged since interpolation now happens in the component against the runtime config.Example manifest snippet that now works:
Declarative-First Evaluation
Not a connector fix: this changes the CDK's own declarative components (
PredicateValidator,ValidateAdheresToSchema) so manifests can use them as documented. No custom component is added; adopters keep using the built-inPredicateValidator/DpathValidator+ValidateAdheresToSchemafrom YAML.Breaking Change Evaluation
Not breaking. No schema, spec, stream, or state change.
PredicateValidatorpreviously crashed when used throughSpec, and plain-string inputs toValidateAdheresToSchemapreviously always raised; both now validate. Valid-JSON strings and non-string values behave as before.Review Spotlight
Reviewers with limited time, please review first:
predicate_validator.py: interpolation and literal parsing ofvaluevalidate_adheres_to_schema.py#L30-L35: raw-string fallbackRisks
JinjaInterpolation'sast.literal_evalstep (same as other interpolated CDK fields), so e.g. a value rendering"123"is validated as the int123. This matches existing interpolation semantics elsewhere in the CDK.ValidateAdheresToSchemastill JSON-decodes strings first, so a string that happens to be valid JSON (e.g."123","true") is validated as the decoded value, not as a string. Plain non-JSON strings (hostnames, URLs) are now validated as-is.source-google-search-console-stylecustom_reportsarray check given malformed JSON), the error is still aValueError, but the message changes fromInvalid JSON string: ...toJSON schema validation error: '...' is not of type 'array'. Valid JSON strings and non-string values behave exactly as before.PredicateValidatorhad no working runtime path before (it raisedTypeError), and no connector inairbytehq/airbyteusestype: PredicateValidatortoday.Follow-ups
ValidateAdheresToSchema.base_schemadeclaresinterpolation_context: [config]butcreate_validate_adheres_to_schemacasts it directly without interpolation. Interpolating it naively would run every schema string (descriptions, patterns) through Jinja +literal_eval, which is not low-risk, so it is left for a separate change.Test plan
unit_tests/sources/declarative/spec/test_spec.pybuild aSpecfrom a manifest snippet viaModelToComponentFactoryand callvalidate_config:{type: array, uniqueItems: true}: pass (unique) and fail (duplicate)PredicateValidatorreads a key from the passed config (pass/fail)DpathValidator+ hostnamepatternschema: valid hostname passes; URL and non-matching host fail withValueErrortest_predicate_validator.py(interpolation, list rendering, literal non-string preservation, nested interpolation) andtest_validate_adheres_to_schema.py(non-JSON string pass/fail).mainand pass with this change; existing validator/spec tests pass unchanged.poetry run pytest unit_tests/sources/declarative(2357 passed, 1 skipped),ruff check,ruff format --check,mypyonvalidators/. The fullunit_tests/suite is left to CI.Link to Devin session: https://app.devin.ai/sessions/b07c9708bfc1453a93f32490f11a5806
Open in Devin Desktop: https://app.devin.ai/desktop/session/b07c9708bfc1453a93f32490f11a5806?variant=devin