Skip to content

🧪 [Testing] Add test for empty errors handling in GraphQLResponse#335

Open
abn wants to merge 2 commits intomainfrom
test-graphqlresponse-errors-2155263628703483964
Open

🧪 [Testing] Add test for empty errors handling in GraphQLResponse#335
abn wants to merge 2 commits intomainfrom
test-graphqlresponse-errors-2155263628703483964

Conversation

@abn
Copy link
Copy Markdown
Owner

@abn abn commented Mar 24, 2026

🎯 What: The GraphQLResponse.errors property was lacking tests covering scenarios where the "errors" key in the payload is either missing or explicitly set to None.
📊 Coverage: Added tests to cover missing "errors" key and explicit {"errors": None} key.
Result: Improved test coverage and reliability of GraphQLResponse's error parsing logic, ensuring it safely handles absent or null error lists.


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

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 Mar 24, 2026
@qodo-code-review
Copy link
Copy Markdown

Review Summary by Qodo

Add tests for GraphQLResponse empty errors handling

🧪 Tests

Grey Divider

Walkthroughs

Description
• Add test for empty errors handling in GraphQLResponse
• Test missing "errors" key returns empty list
• Test explicit None "errors" value returns empty list
• Add mocking dependencies to dev requirements
Diagram
flowchart LR
  A["GraphQLResponse errors property"] -->|missing errors key| B["returns empty list"]
  A -->|errors set to None| C["returns empty list"]
  D["Dev dependencies"] -->|add mocking libs| E["mocket, httpretty"]
Loading

Grey Divider

File Changes

1. tests/test_response.py 🧪 Tests +14/-0

Add empty errors handling tests for GraphQLResponse

• Add new test function test_graphql_response_empty_errors() to verify error handling
• Test case for missing "errors" key in JSON payload
• Test case for explicit "errors": None in JSON payload
• Both test cases assert that errors property returns empty list

tests/test_response.py


2. pyproject.toml Dependencies +2/-0

Add mocking libraries to dev dependencies

• Add mocket version ^3.14.1 to dev dependencies
• Add httpretty version ^1.1.4 to dev dependencies
• Dependencies added to support mocking in tests

pyproject.toml


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Mar 24, 2026

Code Review by Qodo

🐞 Bugs (2) 📘 Rule violations (0) 📎 Requirement gaps (0) 📐 Spec deviations (0)

Grey Divider


Remediation recommended

1. Conflicting mocket constraints🐞 Bug ⚙ Maintainability
Description
mocket is declared in both the dev and test dependency groups with different version
constraints, which makes dependency resolution/lock updates harder and can produce inconsistent
environments depending on which groups are installed.
Code

pyproject.toml[247]

+mocket = "^3.14.1"
Evidence
The PR adds mocket = "^3.14.1" to the dev group, while the repo already declares `mocket =
">=3.13.2"` in the test group. Poetry resolves a single version across installed groups, so having
two constraints is redundant and can cause confusion when updating dependencies or installing
--with dev,test.

pyproject.toml[242-256]

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

## Issue description
`mocket` is specified in multiple Poetry groups with different version constraints.
### Issue Context
This increases maintenance burden and can lead to confusing dependency resolution when multiple groups are installed.
### Fix Focus Areas
- pyproject.toml[242-256]
- Keep `mocket` in a single appropriate group (likely `test`), or make the constraints identical across groups.

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


2. Dev-only httpretty dependency 🐞 Bug ⛯ Reliability
Description
httpretty is added to the dev dependency group, but tox installs only the test group, so this
change will not make httpretty available in CI test runs and may be an unused dependency.
Code

pyproject.toml[248]

+httpretty = "^1.1.4"
Evidence
The tox test env installs dependencies via poetry install --no-root --only=test, which excludes
tool.poetry.group.dev.dependencies. Meanwhile, tests use HTTPretty via `from
mocket.plugins.httpretty import HTTPretty (not import httpretty), so adding the httpretty`
package to the dev group is either ineffective for CI or unnecessary if the tests don’t require the
external package.

pyproject.toml[175-188]
tests/conftest.py[13-17]
tests/test_httpx_transport.py[10-14]

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

## Issue description
`httpretty` is added under the dev dependency group, but the test runner (tox) installs only the test group.
### Issue Context
If `httpretty` is required for tests, it must be in the test group to be present in CI. If it is not required, it should not be added.
### Fix Focus Areas
- pyproject.toml[175-188]
- pyproject.toml[242-256]
- If tests need `httpretty`, add it under `[tool.poetry.group.test.dependencies]`.
- Otherwise, remove it entirely from dev deps to avoid unused supply-chain surface area.

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



Advisory comments

3. Unnecessary request mutation 🐞 Bug ⚙ Maintainability
Description
The new test mutates the frozen GraphQLResponse.request via object.__setattr__, but
GraphQLResponse.errors doesn’t depend on request, so the mutation adds unrelated behavior to
this test and reduces readability.
Code

tests/test_response.py[R10-19]

+    response_no_errors = GraphQLResponse(request="...", json={"data": {}})
+    object.__setattr__(response_no_errors, "request", "...")
+    assert response_no_errors.errors == []
+
+    # Explicit None errors key
+    response_none_errors = GraphQLResponse(
+        request="...", json={"data": {}, "errors": None}
+    )
+    object.__setattr__(response_none_errors, "request", "...")
+    assert response_none_errors.errors == []
Evidence
GraphQLResponse.errors reads only self.json.get("errors").
GraphQLRequestContainer.__post_init__ normalizes a string request into a GraphQLRequest, so the
__setattr__ calls are effectively creating an artificial state that isn't needed for validating
.errors behavior.

tests/test_response.py[8-19]
src/aiographql/client/response.py[46-55]
src/aiographql/client/request.py[91-119]

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

## Issue description
The test for empty/missing errors mutates `GraphQLResponse.request` even though `.errors` does not depend on it.
### Issue Context
This makes the test less focused and slightly harder to understand.
### Fix Focus Areas
- tests/test_response.py[8-19]
- Remove `object.__setattr__(..., "request", ...)` lines from this specific test.
- Keep the separate `query` test (which explicitly needs a string request) as-is.

ⓘ 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 Mar 24, 2026
Co-authored-by: abn <165325+abn@users.noreply.github.com>
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