Skip to content

πŸ›‘οΈ Shield: Fix Paginator crash on invalid 'pagination' field#714

Merged
fderuiter merged 2 commits intomainfrom
shield-fix-paginator-crash-11431631424112267383
Feb 26, 2026
Merged

πŸ›‘οΈ Shield: Fix Paginator crash on invalid 'pagination' field#714
fderuiter merged 2 commits intomainfrom
shield-fix-paginator-crash-11431631424112267383

Conversation

@fderuiter
Copy link
Owner

πŸ›‘ Vulnerability: The BasePaginator class previously crashed with an AttributeError: 'str' object has no attribute 'get' if the API returned a pagination field that was not a dictionary (e.g., a string or list). This occurred because the code blindly attempted to call .get("totalPages") on the value.

πŸ›‘οΈ Defense: Modified imednet/core/paginator.py to explicitly check if pagination is a dictionary (when not None). If it is invalid, a TypeError is now raised with a clear message: Response field 'pagination' must be a dictionary, got {type(pagination).__name__}.

πŸ”¬ Verification:

  1. Added a new test case test_paginator_raises_type_error_on_invalid_pagination_field in tests/unit/test_paginator_robustness.py.
  2. Verified that the test fails (reproduces the crash) without the fix.
  3. Verified that the test passes with the fix.
  4. Ran the full test suite (pytest) to ensure no regressions.

πŸ“Š Impact: eliminating a potential runtime crash and providing better error visibility for API contract violations.


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

- Update `BasePaginator._next_page` to validate that the `pagination` field in the API response is a dictionary.
- Raise `TypeError` with a descriptive message if `pagination` is present but invalid (e.g., a string), preventing `AttributeError` crashes.
- Add regression test `test_paginator_raises_type_error_on_invalid_pagination_field` in `tests/unit/test_paginator_robustness.py`.

This change ensures the paginator fails gracefully with a meaningful error when the API returns an unexpected structure, aiding in debugging and preventing runtime crashes.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
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.

- Format `tests/unit/test_paginator_robustness.py` to comply with the project's `black` and `isort` configuration.
- Fixes CI failure in 'Quality & Security' workflow.

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 26, 2026 19:00
@fderuiter fderuiter merged commit 65c97a5 into main Feb 26, 2026
13 checks passed
@fderuiter fderuiter deleted the shield-fix-paginator-crash-11431631424112267383 branch February 26, 2026 19:00
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