fix(redis): preserve empty-string values in getHashFieldsBatch#4060
fix(redis): preserve empty-string values in getHashFieldsBatch#4060fuleinist wants to merge 1 commit into
Conversation
What was wrong and what this fixes. ## Changes - server/_shared/redis.ts: replace the truthy check on HMGET results (if (values[i])) with a null/undefined check (if (values[i] != null)) so valid empty-string Redis hash values are no longer silently dropped. - tests/redis-caching.test.mjs: add a regression test that mocks the HMGET pipeline response with a mix of real values, '', and null, and asserts that '' is preserved in the returned Map. ## Testing - [x] Unit test added for the bug (tests/redis-caching.test.mjs) - [x] Test fails on the unfixed code (verified) - [x] Test passes on the fixed code (verified; 29/29 green) - [x] Existing tests still pass (28 prior tests still green) Fixes koala73#3530
|
@fuleinist is attempting to deploy a commit to the World Monitor Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes a correctness bug in
Confidence Score: 5/5Safe to merge — the change is a minimal, well-tested correctness fix with no behavioral change for existing callers that store non-empty strings. The fix is a single-character change from a truthy guard to a null-equality guard. Existing callers are unaffected because they store non-empty JSON or string values. The new regression test covers all four possible HMGET response states. No edge cases are introduced. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant getHashFieldsBatch
participant Upstash REST API
Caller->>getHashFieldsBatch: key, fields ["name","empty","missing","real"]
getHashFieldsBatch->>Upstash REST API: POST /pipeline [["HMGET", key, ...fields]]
Upstash REST API-->>getHashFieldsBatch: [{result: ["alice", "", null, "ok"]}]
note over getHashFieldsBatch: for each i: if (values[i] != null)<br/> → "" passes (fix)<br/> → null is skipped
getHashFieldsBatch-->>Caller: "Map { "name"→"alice", "empty"→"", "real"→"ok" }"
Reviews (1): Last reviewed commit: "fix(redis): preserve empty-string values..." | Re-trigger Greptile |
Summary
getHashFieldsBatchinserver/_shared/redis.tsused a truthy check (if (values[i])) on HMGET pipeline results. That treats the empty string""the same asnull/ missing, so any caller that legitimately stores an empty-string hash value in Redis silently loses it on read.This is a one-line correctness fix: switch the truthy check to a null/undefined check (
if (values[i] != null)) so""round-trips intact.Problem
Upstash's HMGET pipeline response is
Array<(string | null)>in field order —nullmeans the key is missing, and any string (including"") is the stored value. The truthy check cannot distinguish "field is present and empty" from "field is missing", so the caller gets an emptyMapfor the affected key instead ofMap { field -> "" }.Current callers store JSON or non-empty strings so the bug is rarely hit, but it will surprise the next caller that legitimately needs to round-trip an empty string.
Solution
!= nullmatches bothnullandundefinedand is the idiomatic way to express "value is present" in TypeScript.Testing
tests/redis-caching.test.mjs)undefined !== '')New test asserts the full HMGET return mix:
Files Changed
server/_shared/redis.ts— 1 line changed, 2 lines of comment addedtests/redis-caching.test.mjs— 47 lines added (newdescribeblock)Fixes #3530