fix container group caching issues#531
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes container group caching issues by converting service group generators into lists, ensuring that subsequent calls yield consistent results. It also adds a corresponding unit test and updates the app composition to include an additional groups plugin.
- Fix caching issue by caching the list instead of an exhausted generator.
- Add unit tests to validate the correct behavior.
- Update container composition by using a composite container to include the groups plugin.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| rats-apps/test/rats_test/apps/test_service_caching.py | Added unit tests for group caching behavior. |
| rats-apps/test/rats_test/apps/example/_app.py | Updated container composition to include ExampleGroupsPlugin1. |
| rats-apps/src/rats/apps/_container.py | Modified caching strategy by converting generators to lists for specific namespaces. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
the problem with caching an iterator or a list, is that the group cannot later change? Should we cache the objects rather than the group itself? Otherwise, I am happy to proceed with the PR if it unblocks you. |
jzazo
left a comment
There was a problem hiding this comment.
See comment on caching the items rather than the group
not sure i understood, service providers are always immutable and never change, so our goal is to cache all the calls to get a service or group. |
|
I guess service providers are always immutable, that includes groups? If that's the premise, go ahead and cache the group as a list/tuple. |
calling
rats.apps.Container.get_group()a second time for a given service id was returning an empty list, because we're caching the group generator, which gets exhausted after the first time looping through results. fixed by caching the list instead of the generator. also added a unit test for this behavior.