redis / redis/node-redis

Silent error when setting an `undefined` value with `HMSET` inside a transaction

Open
#2,108 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
TypeScript
Stars
17.6k
Forks
2k
Avg merge
2d 3h
Merged PRs (30d)
40

Description

Environment:

  • Node.js Version: 16.14.0
  • Redis Server Version: 5.0.7
  • Node Redis Version: 3.1.2
  • Platform: Ubuntu 20.04.3

When setting an undefined value in a hash with HSET or HMSET, an error will result. This is to be expected.

redis.hmset ('test', {a: 'b', c: undefined}, console.log);
Error: node_redis: The HMSET command contains a invalid argument type of "undefined".
Only strings, dates and buffers are accepted. Please update your code to use valid argument types.

When doing the same thing inside a multi block, however, no error will be reported.

var multi = redis.multi ();
multi.hmset ('test', {a: 'b', c: undefined});
multi.exec (function (error) {console.log ('Error: ' + error)})
Error: null

Within the context of a HSET, this wouldn't be an issue because there's a single field to be set. However, because it's an HMSET, the other fields would be expected to be set.

This is particularly problematic because in older versions of node-redis (or perhaps of both node-redis and redis itself) any undefined values in a field would be ignored, while the other ones would still be set. In the examples above, using this older version(s), within the test hash, field a would have been set to b. Anyone relying on the above behavior would silently encounter a scenario where the HMSET operation doesn't happen at all, without any warning. That's actually what happened to me :|

This issue is probably related to #689

In closing, I'd like to thank the original author and the team for writing and maintaining node-redis, which I find to be a spectacular piece of software and a core part of my stack. I've used it heavily for 9+ years and this is the first issue (or perhaps surprise) I have encountered. Thank you.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the HMSET examples with an undefined value both directly and through multi/exec. Trace the HMSET argument validation and transaction execution paths; done means the invalid argument is no longer silently accepted inside a transaction and the reported behavior is covered by an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, redis
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.