Skip to content

🧪 test: add explicit test for GraphQLRequest __getattr__ fallback#334

Open
abn wants to merge 2 commits intomainfrom
testing-graphqlrequest-getattr-fallback-14089311927115356430
Open

🧪 test: add explicit test for GraphQLRequest __getattr__ fallback#334
abn wants to merge 2 commits intomainfrom
testing-graphqlrequest-getattr-fallback-14089311927115356430

Conversation

@abn
Copy link
Copy Markdown
Owner

@abn abn commented Mar 24, 2026

🎯 What: The testing gap for testing invalid attribute access directly on GraphQLRequest.__getattr__ was addressed. Previously, it was buried in another test.
📊 Coverage: The scenario where a user attempts to access an undefined attribute on GraphQLRequest is now explicitly tested and isolated.
Result: Improved test separation and clarity, ensuring the __getattr__ implementation relies on super().__getattribute__ behavior correctly.


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

Extracted the __getattr__ fallback validation logic (testing that accessing an invalid attribute raises an AttributeError) from `test_graphql_request_asdict` into its own specific test case `test_graphql_request_getattr_fallback`. This improves testing clarity and focuses the test suite on specific behaviors.

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

Extract GraphQLRequest getattr fallback into dedicated test

🧪 Tests

Grey Divider

Walkthroughs

Description
• Extracted __getattr__ fallback test into dedicated test function
• Improves test clarity by isolating attribute error behavior
• Removes mixed concerns from test_graphql_request_asdict
Diagram
flowchart LR
  A["test_graphql_request_asdict"] -- "extract AttributeError check" --> B["test_graphql_request_getattr_fallback"]
  A -- "keep asdict validation" --> A
Loading

Grey Divider

File Changes

1. tests/test_request.py 🧪 Tests +7/-3

Isolate GraphQLRequest attribute error test

• Removed __getattr__ fallback test (AttributeError check) from test_graphql_request_asdict
• Created new dedicated test function test_graphql_request_getattr_fallback
• New test validates that accessing non-existent attributes raises AttributeError
• Improves test separation and focuses each test on specific behavior

tests/test_request.py


Grey Divider

Qodo Logo

@qodo-code-review
Copy link
Copy Markdown

qodo-code-review Bot commented Mar 24, 2026

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Misnamed getattr test 🐞 Bug ⚙ Maintainability
Description
test_graphql_request_getattr_fallback is named as if it validates GraphQLRequest.__getattr__,
but GraphQLRequest does not define __getattr__; missing attribute access is handled by
__getattribute__ delegating to super().__getattribute__. This makes the test
intent/documentation inaccurate and may mislead future maintenance or refactors.
Code

tests/test_request.py[R64-69]

+def test_graphql_request_getattr_fallback() -> None:
+    request = GraphQLRequest(query="{ city { name } }", operation="GetCity")
+
+    with pytest.raises(AttributeError):
+        _ = request.non_existent
+
Evidence
The added test asserts an AttributeError on request.non_existent. However, GraphQLRequest only
overrides __getattribute__ and does not implement __getattr__, so the exception is produced by
the default attribute lookup path through super().__getattribute__, not a __getattr__ fallback.

src/aiographql/client/request.py[15-46]
tests/test_request.py[64-69]

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

### Issue description
`test_graphql_request_getattr_fallback` implies `GraphQLRequest.__getattr__` exists/was exercised, but `GraphQLRequest` only overrides `__getattribute__`. The test is valid, but its naming/intent is inaccurate.

### Issue Context
`GraphQLRequest` implements a custom `__getattribute__` for the `operation` alias, and delegates all other attribute access to `super().__getattribute__`, which raises `AttributeError` for missing attributes.

### Fix Focus Areas
- tests/test_request.py[64-70]
- src/aiographql/client/request.py[42-46]

### Suggested change
Rename the test to something accurate, e.g.:
- `test_graphql_request_missing_attribute_raises`
- `test_graphql_request_attribute_error_on_unknown_attr`
- `test_graphql_request_getattribute_fallback` (if you want to emphasize the mechanism)

Optionally, align PR title/description with `__getattribute__` rather than `__getattr__`.

ⓘ 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

Extracted the __getattr__ fallback validation logic (testing that accessing an invalid attribute raises an AttributeError) from `test_graphql_request_asdict` into its own specific test case `test_graphql_request_getattr_fallback`. This improves testing clarity and focuses the test suite on specific behaviors.

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

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