KV giving null while doing get even though the key exists
There is no error from KV and also there is no response with correct value.
15 Replies
You'll probably need to give us more context on the problem. Do you have a code sample or something? Are you testing locally or are you working in production?
Production
@JustinNoel The code snippet is as follows:
Here is the sample code... Sometimes, I'm getting null in the
then
part of the response, not the catch
part. So the request is successful while the return response from kv is null even though there is value for the said keyErrors are only thrown when something goes wrong internally. Since a
get
of an empty key isn't wrong, then no error is thrown.
Also, you seem to be combining await and thenAre you testing locally or are you working in production?
The key itself is present and has value in kv store
Mistake on my part
Production
No, I just meant that, if a key wasn't present, that wouldn't be an error, so it wouldn't hit the
catch
handler.
How long has it been since it was inserted/updated? Updates can take 60 seconds or more to show up, depending on how recently you tried to access the key, and what cacheTtl
you set, if any.Right
About 1 week
Try just doing this:
If you to catch errors, I would suggest using a try catch instead of then and catch.
I'm not getting error. The kv is just returning null even though value for the key exists
How do you know it exists?
By directly checking in the KV store, by searching with the key
Is
KV_NAME
bound to the correct KV namespace?Yes
Can you sanity check that by adding something in the KV web view and then trying to retrieve it in your code? I very much suspect there is an issue on your side somewhere.
I did do that too... No dice