-
Notifications
You must be signed in to change notification settings - Fork 0
Refactor ListEndpointMixin into focused mixins #641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor ListEndpointMixin into focused mixins #641
Conversation
- Extracted `ParamMixin` to handle parameter resolution and filtering logic. - Extracted `CacheMixin` to handle caching logic. - `ListEndpointMixin` now composes these mixins, adhering to SRP. - Verified with existing tests in `tests/unit/endpoints/test_list_get.py`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Extracted `ParamMixin` to handle parameter resolution and filtering logic. - Extracted `CacheMixin` to handle caching logic. - `ListEndpointMixin` now composes these mixins, adhering to SRP. - Verified with existing tests in `tests/unit/endpoints/test_list_get.py`. - Fixed formatting issues with `black` and `isort`. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors ListEndpointMixin in imednet/core/endpoint/mixins.py by splitting parameter/filter handling and caching logic into two dedicated mixins (ParamMixin and CacheMixin) while keeping the list execution flow in ListEndpointMixin.
Changes:
- Extracted cache-related helpers into
CacheMixin(_get_local_cache,_check_cache_hit,_update_local_cache). - Extracted filter/param normalization into
ParamMixin(_resolve_params,_extract_special_paramshook). - Updated
ListEndpointMixin._list_implto use the new mixins for param resolution and cache handling.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| study, params, other_filters = self._resolve_params(study_key, extra_params, filters) | ||
|
|
||
| # Cache Hit Check | ||
| if self.requires_study_key: | ||
| if not study: | ||
| # Should have been caught in _prepare_list_params but strict typing requires check | ||
| raise ValueError("Study key must be provided or set in the context") | ||
| if cache is not None and not other_filters and not refresh and study in cache: | ||
| return cast(List[T], cache[study]) | ||
| else: | ||
| if cache is not None and not other_filters and not refresh: | ||
| return cast(List[T], cache) | ||
| cache = self._get_local_cache() | ||
| cached_result = self._check_cache_hit(study, refresh, other_filters, cache) | ||
| if cached_result is not None: | ||
| return cast(List[T], cached_result) |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_list_impl no longer has the explicit guard that study must be present when requires_study_key is true (the old implementation raised immediately). Since _resolve_params can still return a falsy study (e.g. when _pop_study_filter is enabled and the caller passes studyKey=None/"" in filters), this can produce paths like /.../None/... and cache entries keyed under None. Add a strict check here (or in _resolve_params) to raise the same missing-study error before attempting cache/path/pagination work.
| study, params, other_filters = self._resolve_params(study_key, extra_params, filters) | ||
|
|
||
| # Cache Hit Check | ||
| if self.requires_study_key: | ||
| if not study: | ||
| # Should have been caught in _prepare_list_params but strict typing requires check | ||
| raise ValueError("Study key must be provided or set in the context") | ||
| if cache is not None and not other_filters and not refresh and study in cache: | ||
| return cast(List[T], cache[study]) | ||
| else: | ||
| if cache is not None and not other_filters and not refresh: | ||
| return cast(List[T], cache) | ||
| cache = self._get_local_cache() | ||
| cached_result = self._check_cache_hit(study, refresh, other_filters, cache) | ||
| if cached_result is not None: | ||
| return cast(List[T], cached_result) |
Copilot
AI
Feb 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a unit test for the requires_study_key + _pop_study_filter path where studyKey is provided but falsy (e.g. studyKey=None or empty string via **filters). This refactor removed the explicit study validation from _list_impl, so a targeted test would help ensure missing/invalid study keys are still rejected consistently and don’t lead to /None/ paths or incorrect caching.
This refactoring splits the
ListEndpointMixininimednet/core/endpoint/mixins.pyinto smaller, more focused mixins (ParamMixinandCacheMixin). This improves the maintainability and testability of the code by adhering to the Single Responsibility Principle. The logic for parameter handling and caching is now decoupled from the main list execution flow. No behavior changes were introduced.PR created automatically by Jules for task 5224798271895880288 started by @fderuiter