updateAttributes on jugglingdb-redis breaks index for non-string fields
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, redis
- Domain
- databases
Research direction
The bug is in lib/redis.js line 291, where a strict inequality comparison (!==) between a string from prevData and a non-string new value incorrectly triggers index removal. Start by examining the updateAttributes flow, focusing on how prevData is populated via hgetall and how index updates are handled. Verify the fix by modifying the comparison to handle type coercion, then test with a model that has a numeric indexed field to ensure the index persists after an update.
Written by the indexing model from the issue text.
Description
Thank you for all your hard work. I ran into an issue with the jugglingdb-redis adapter. I have several fields that are defined such as:
status: { type: Number, default: 1, index: true }
When I create an instance of the object with that field it saves fine and I can see in the store that there is an index created. However if I call updateAttributes on the same instance later the index actually disappears. I've debugged this and traced it back to the following code: redis.js Line291. It compares the value being saved with the previous value and if they are different it adds the new one and removes the old one. The problem is it uses a !== for comparison so even though you could be passing the same value it will be removed if it is a number, or date or anything but a string. All keys and values in prevData are strings because they come from the hash that was retrieved with a hgetall at line 260. So when you try to do a findOne later on status it fails because it was removed from the index.
Let me know if this makes sense. I'd love to have this working so that I can use numbers, booleans, etc. and still search on them even after updating the records.
- Dominant language
- JavaScript
- Stars
- 2k
- Forks
- 238
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from 1602/jugglingdb
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
1602/jugglingdb#290 ·
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
1602/jugglingdb#465 ·
-
Use in production? Open
Difficulty 1/5 Under an hour Newbie friendliness 30/100
1602/jugglingdb#464 · 2 comments · 1 reaction ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
1602/jugglingdb#461 · 3 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
1602/jugglingdb#457 ·
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·