fix: await Redis EXISTS call in RedisAdapter.hasKey()#684
Open
Priyanshubhartistm wants to merge 1 commit into
Open
fix: await Redis EXISTS call in RedisAdapter.hasKey()#684Priyanshubhartistm wants to merge 1 commit into
Priyanshubhartistm wants to merge 1 commit into
Conversation
Signed-off-by: Priyanshubhartistm <bhartipriyanshustm@gmail.com>
🦋 Changeset detectedLatest commit: 32fafc1 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RedisAdapter.hasKey()calledthis.client.exists(key)withoutawaitand wrapped the result inBoolean(). Sinceclient.exists()returns aPromise<number>,Boolean(promise)is alwaystrue(a non-null object is truthy) regardless of whether the key actually exists in Redis. Fixed by awaiting the call and comparing the resolved count to0.Additionally, the existing unit tests for
hasKeystubbedclient.existswith sinon's.returns()(a plain synchronous value) rather than.resolves()(an actual Promise, matching the real Redis client's behavior). This masked the bug entirely — both tests passed against the broken implementation purely becauseBoolean(1)andBoolean(0)happened to match the expected true/false values. Updated both stubs to.resolves()so they exercise the real async path.Related Issue
#683
Motivation and Context
hasKey()always returningtruemeans any caller using it as a cache-presence check would incorrectly treat every key as present. The issue notes this previously forced a full Postgres lookup on every event (the call site had to be commented out because the method didn't work). While the codebase has since moved that particular admission-cache check togetKey()instead,hasKey()remains a public method onICacheAdapterand should behave correctly for any current or future caller.How Has This Been Tested?
hasKeyunit tests to stubclient.existswith.resolves()instead of.returns(), and verified (by temporarily reverting the source fix) that the corrected test now fails against the old buggy code withAssertionError: expected true to be false— proving it actually catches this regression.pnpm run test:unit— 1393 passing.pnpm run test:cli— 73 passing.pnpm run cover:unit— passes.pnpm lint,pnpm exec biome format(on the touched files),pnpm check:deps,pnpm run build:check,pnpm run build, and `pnpm run verify:cli:buhasKey()is not called anywhere incurrent production code paths (the admission-cache check in
event-megetKey()` instead), so this change has no reachable integration surface.Screenshots (if appropriate):
N/A — backend-only change, no UI impact.
Types of changes
Checklist: