Skip to content

🧪 testing improvement: Add test for Pydantic model validation failure in codec.decode#343

Open
abn wants to merge 2 commits intomainfrom
test-improvement/pydantic-validation-16876072726510236073
Open

🧪 testing improvement: Add test for Pydantic model validation failure in codec.decode#343
abn wants to merge 2 commits intomainfrom
test-improvement/pydantic-validation-16876072726510236073

Conversation

@abn
Copy link
Copy Markdown
Owner

@abn abn commented Apr 2, 2026

🎯 What: The testing gap addressed
The issue highlighted that the Pydantic model validation failure handling code in src/aiographql/client/codec.py:184 was untested. When target_type.model_validate(value) fails, it raises an exception which is caught and re-raised as a GraphQLCodecException.

📊 Coverage: What scenarios are now tested
A test was added, test_pydantic_decode_validation_exception_fallback, which uses pytest_mock.MockerFixture to mock the model_validate method of the target Pydantic model, forcing it to throw an exception during codec.decode(). It correctly catches the exception and tests the wrapper GraphQLCodecException.

Result: The improvement in test coverage
The exception block is now fully covered, ensuring that lines 184-187 in codec.py are properly tested. The local codec unit tests passed with 100% coverage on these lines.


PR created automatically by Jules for task 16876072726510236073 started by @abn

Tested the exception block handling Pydantic `model_validate` failures
by mocking the method to throw a generic exception. Ensures coverage of
lines 184-187 in `aiographql/client/codec.py`.

Co-authored-by: abn <165325+abn@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 2, 2026
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add test for Pydantic validation failure in codec.decode

🧪 Tests

Grey Divider

Walkthroughs

Description
• Add test for Pydantic model validation failure handling
• Mock model_validate to throw exception and verify wrapping
• Ensure coverage of exception handling in codec.decode
Diagram
flowchart LR
  A["Test Setup"] -- "Mock model_validate" --> B["Force Exception"]
  B -- "Call codec.decode" --> C["Catch GraphQLCodecException"]
  C -- "Verify error message" --> D["Coverage Complete"]
Loading

Grey Divider

File Changes

1. tests/test_pydantic_codec.py 🧪 Tests +18/-0

Add Pydantic validation failure exception test

• Added new test function test_pydantic_decode_validation_exception_fallback
• Uses pytest-mock to mock model_validate method to raise exception
• Verifies that codec.decode catches and wraps exception as GraphQLCodecException
• Asserts both the wrapper message and original error message are present

tests/test_pydantic_codec.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Apr 2, 2026

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Missing trailing comma 🐞 Bug ⚙ Maintainability
Description
The newly-added multi-line mocker.patch.object(...) call is not ruff-format/Black compliant
because it omits the trailing comma on the last argument. This will cause ruff-format (configured
in pre-commit) to rewrite the file and can fail formatting checks where enforced.
Code

tests/test_pydantic_codec.py[R167-171]

+    mocker.patch.object(
+        user_profile_model,
+        "model_validate",
+        side_effect=Exception("Unexpected mock validation error")
+    )
Evidence
The added test introduces a multi-line function call whose last argument line lacks a trailing
comma, which ruff-format will normalize. The repository has a pre-commit hook configured to run
ruff-format, meaning contributors (and any CI running pre-commit/format checks) will see this as a
formatting failure until fixed.

tests/test_pydantic_codec.py[162-171]
.pre-commit-config.yaml[1-8]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
A multi-line `mocker.patch.object(...)` call is missing a trailing comma after the final keyword argument, which is not compliant with `ruff-format` (Black-style formatting).

### Issue Context
The repo uses a `ruff-format` pre-commit hook; this change will be reformatted automatically and may fail formatting checks when enforced.

### Fix Focus Areas
- tests/test_pydantic_codec.py[167-171]

### Suggested change
Add a trailing comma after `side_effect=Exception(...)` so the call formats cleanly:
```py
mocker.patch.object(
   user_profile_model,
   "model_validate",
   side_effect=Exception("Unexpected mock validation error"),
)
```
Then run `ruff-format` (or pre-commit) to confirm formatting is clean.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

@dosubot dosubot Bot added the python Pull requests that update Python code label Apr 2, 2026
Comment on lines +167 to +171
mocker.patch.object(
user_profile_model,
"model_validate",
side_effect=Exception("Unexpected mock validation error")
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Remediation recommended

1. Missing trailing comma 🐞 Bug ⚙ Maintainability

The newly-added multi-line mocker.patch.object(...) call is not ruff-format/Black compliant
because it omits the trailing comma on the last argument. This will cause ruff-format (configured
in pre-commit) to rewrite the file and can fail formatting checks where enforced.
Agent Prompt
### Issue description
A multi-line `mocker.patch.object(...)` call is missing a trailing comma after the final keyword argument, which is not compliant with `ruff-format` (Black-style formatting).

### Issue Context
The repo uses a `ruff-format` pre-commit hook; this change will be reformatted automatically and may fail formatting checks when enforced.

### Fix Focus Areas
- tests/test_pydantic_codec.py[167-171]

### Suggested change
Add a trailing comma after `side_effect=Exception(...)` so the call formats cleanly:
```py
mocker.patch.object(
    user_profile_model,
    "model_validate",
    side_effect=Exception("Unexpected mock validation error"),
)
```
Then run `ruff-format` (or pre-commit) to confirm formatting is clean.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests that update Python code size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant