Skip to content

πŸ›‘οΈ Shield: Harden BasePaginator against invalid API response types#694

Merged
fderuiter merged 2 commits intomainfrom
shield/harden-paginator-types-1425226114975248875
Feb 23, 2026
Merged

πŸ›‘οΈ Shield: Harden BasePaginator against invalid API response types#694
fderuiter merged 2 commits intomainfrom
shield/harden-paginator-types-1425226114975248875

Conversation

@fderuiter
Copy link
Copy Markdown
Owner

πŸ›‘ Vulnerability: The BasePaginator implicitly assumed API responses were always dictionaries, leading to obscure AttributeErrors when the API returned lists, strings, or other types. It also assumed the data under data_key was always a list.

πŸ›‘οΈ Defense: Modified imednet/core/paginator.py to explicitly validate that the response payload is a dictionary and the extracted items are a list. It now raises a clear TypeError with helpful context if these expectations are not met.

πŸ”¬ Verification: Added tests/unit/test_paginator_robustness.py which mocks the client to return invalid response types (list, scalar, invalid data key) and asserts that the expected TypeError is raised. Ran pytest tests/unit/test_paginator_robustness.py to confirm.

πŸ“Š Impact: eliminating fragility in pagination logic by converting runtime crashes into handled exceptions. Increases code confidence by handling known "sad paths".


PR created automatically by Jules for task 1425226114975248875 started by @fderuiter

The BasePaginator previously assumed that API responses would always be
dictionaries containing a list under the specified data key. This assumption
could lead to confusing `AttributeError`s (e.g., `'str' object has no
attribute 'get'`) when the API returned unexpected types like lists or
scalars.

This change adds explicit type validation in `_extract_items`. It now raises
a descriptive `TypeError` if:
1. The response payload is not a dictionary.
2. The extracted items under `data_key` are not a list.

This improves robustness and debuggability when dealing with malformed
responses or unexpected API behavior.

Added `tests/unit/test_paginator_robustness.py` to cover these sad paths.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@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.

Applied `black` and `isort` to `imednet/core/paginator.py` and
`tests/unit/test_paginator_robustness.py` to fix CI failures.

Original context:
Harden BasePaginator against invalid API responses by adding explicit type
validation in `_extract_items`. It now raises a descriptive `TypeError` if
the response payload is not a dictionary or if the extracted items are not
a list.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@fderuiter fderuiter marked this pull request as ready for review February 23, 2026 16:04
@fderuiter fderuiter merged commit 845f05e into main Feb 23, 2026
13 checks passed
@fderuiter fderuiter deleted the shield/harden-paginator-types-1425226114975248875 branch February 23, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant