dataconnect(fix): CACHE_ONLY was incorrectly ignored when cache was not enabled - #8214
Conversation
…red when cache was not enabled [no ci]
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request ensures that queries executed with FetchPolicy.CACHE_ONLY fail as expected when local caching is not enabled or configured, rather than falling back to SERVER_ONLY behavior. To achieve this, a check was added to throw a CachedDataNotFoundException if cacheInfo is null and the fetch policy is CACHE_ONLY. The logic for handling missing cache data was also refactored, and a unit test was added to verify this behavior. I have no feedback to provide as the changes are correct and no review comments were provided.
📝 PRs merging into main branchOur main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released. |
This PR fixes a bug in Data Connect where queries executed with
FetchPolicy.CACHE_ONLYwould incorrectly fall back to performing a server request when local caching was not enabled, instead of failing with an exception as expected. Now,CACHE_ONLYqueries will immediately fail with aCachedDataNotFoundExceptionif caching is not configured.Highlights
FetchPolicy.CACHE_ONLYimmediately throw aCachedDataNotFoundExceptionwhen local caching is not configured on theFirebaseDataConnectinstance.FetchPolicy.CACHE_ONLYto immediately follow the local cache lookup, improving code readability.cacheSettingsin theDataConnectSettingsobject) when they intend to useFetchPolicy.CACHE_ONLY.FetchPolicy.CACHE_ONLYthrows the expected exception and does not execute gRPC requests on the server when 8000 caching is disabled.Changelog
FetchPolicy.CACHE_ONLYnow correctly fail when local caching is disabled instead of falling back to the server.FetchPolicy.CACHE_ONLYand throw a detailedCachedDataNotFoundExceptionif it is not.FetchPolicy.CACHE_ONLYto check for empty results immediately after attempting to retrieve the query from the cache.executeQuery(fetchPolicy=CACHE_ONLY) with null cacheSettings throws CachedDataNotFoundExceptionto assert that cache-only queries correctly fail and never invoke gRPC endpoints when caching is disabled.