Skip to content

feat: update DpathValidator to skip validation if returned value is falsy #590

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

Conversation

pnilan
Copy link
Contributor

@pnilan pnilan commented Jun 6, 2025

What

  • DpathValidator does not invoke validation strategy if value at specified path is falsy

How

value = dpath.get(data, path)
if not value:
   return
...
validate()

Important

Auto-merge enabled.

This PR is set to merge automatically when all requirements are met.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation handling to prevent unnecessary validation attempts when no matching data is found, avoiding errors on empty or missing values.
  • Tests

    • Added tests to ensure validation is skipped when no values are present for specified paths.

@pnilan pnilan requested a review from brianjlai June 6, 2025 21:23
@pnilan pnilan marked this pull request as ready for review June 6, 2025 21:23
@github-actions github-actions bot added the enhancement New feature or request label Jun 6, 2025
@Copilot Copilot AI review requested due to automatic review settings June 6, 2025 21:23
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates DpathValidator to skip validation when the extracted value(s) at the specified path are falsy, and adds a unit test to cover no-value scenarios.

  • Added guards in DpathValidator.validate to return early if dpath.values or dpath.get yield falsy results.
  • Introduced a new test to verify that the validation strategy isn’t called when there are no values.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
unit_tests/sources/declarative/validators/test_dpath_validator.py Added test_given_no_values_when_validate_then_validate_is_not_called to ensure no validation on missing paths
airbyte_cdk/sources/declarative/validators/dpath_validator.py Added if not values/value: return checks to skip validation when results are falsy
Comments suppressed due to low confidence (2)

unit_tests/sources/declarative/validators/test_dpath_validator.py:104

  • Add tests for legitimate falsy values (e.g., 0, False, empty string) to ensure they are handled as intended rather than skipped incorrectly.
assert not strategy.validate_called

airbyte_cdk/sources/declarative/validators/dpath_validator.py:59

  • This check will skip validation for all falsy values (e.g., 0, False, ""). If the intent is to only skip when the value is missing, use if value is None:.
if not value:

Copy link
Contributor

@brianjlai brianjlai left a comment

Choose a reason for hiding this comment

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

do we need to do the same for predicate value or no?

But not blocking, lgtm!

@pnilan
Copy link
Contributor Author

pnilan commented Jun 6, 2025

@brianjlai Hm. I'm on the fence if it's needed there. Couldn't the connector dev include a condition in the provided interpolation value (or does jinja not allow if/then statements?)

Either way, this can be a follow-up.

@pnilan pnilan enabled auto-merge (squash) June 6, 2025 21:28
Copy link

github-actions bot commented Jun 6, 2025

PyTest Results (Fast)

3 658 tests  +1   3 648 ✅ +1   5m 43s ⏱️ -5s
    1 suites ±0      10 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit b074084. ± Comparison against base commit f398ab6.

Copy link
Contributor

coderabbitai bot commented Jun 6, 2025

📝 Walkthrough

Walkthrough

The DpathValidator's validate method was updated to return early if no values are found at the specified path, both for wildcard and non-wildcard cases. Corresponding unit tests were added to ensure that the validation strategy is not called when no matching values exist.

Changes

File(s) Change Summary
airbyte_cdk/sources/declarative/validators/dpath_validator.py Modified validate to return early if no values are found at the dpath, preventing unnecessary calls.
unit_tests/sources/declarative/validators/test_dpath_validator.py Added a test to verify that validation is not called when no values are found at the specified dpath.

Suggested labels

airbyte-python-cdk, declarative-component-schema

Would you like to consider adding more test cases for other edge scenarios, such as when the dpath points to a falsy but present value (e.g., empty string or zero), wdyt?

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f398ab6 and b074084.

📒 Files selected for processing (2)
  • airbyte_cdk/sources/declarative/validators/dpath_validator.py (1 hunks)
  • unit_tests/sources/declarative/validators/test_dpath_validator.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
airbyte_cdk/sources/declarative/validators/dpath_validator.py (3)
unit_tests/sources/declarative/validators/test_dpath_validator.py (1)
  • validate (18-22)
airbyte_cdk/sources/declarative/validators/validation_strategy.py (1)
  • validate (15-22)
airbyte_cdk/sources/declarative/validators/validator.py (1)
  • validate (11-18)
unit_tests/sources/declarative/validators/test_dpath_validator.py (2)
unit_tests/sources/declarative/validators/test_predicate_validator.py (2)
  • MockValidationStrategy (9-20)
  • validate (16-20)
airbyte_cdk/sources/declarative/validators/dpath_validator.py (1)
  • validate (35-63)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Check: 'source-shopify' (skip=false)
  • GitHub Check: Check: 'source-pokeapi' (skip=false)
  • GitHub Check: Check: 'source-amplitude' (skip=false)
  • GitHub Check: Check: 'source-hardcoded-records' (skip=false)
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
🔇 Additional comments (1)
airbyte_cdk/sources/declarative/validators/dpath_validator.py (1)

50-51: Early return logic for wildcard paths looks good!

The check for empty values list makes sense here - no point validating when there's nothing to validate. This aligns well with the PR objective.

Copy link

github-actions bot commented Jun 6, 2025

PyTest Results (Full)

3 661 tests   3 651 ✅  17m 28s ⏱️
    1 suites     10 💤
    1 files        0 ❌

Results for commit b074084.

@pnilan pnilan merged commit 99a1a96 into main Jun 6, 2025
31 of 32 checks passed
@pnilan pnilan deleted the pnilan/feat/update-validator-to-skip-validation-if-value-is-falsy branch June 6, 2025 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants