Dataloader.KV: load new items when results are non-empty #75
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.
Fixes issue #74.
Map.get/2
will either return somevalue()
ornil
.dataloader/lib/dataloader/kv.ex
Lines 85 to 88 in 56f7cb4
The above
case
statement does not specifically handlenil
, because it (incorrectly) expects to find either an:error
2-tuple or a cached result.However, when
fetch/3
is called byload/3
, it is possible that:results
is a non-empty map, andresults
entry matchingid
In that case,
Map.get/2
would returnnil
, but it was being pattern-matched as a positive result instead of an error, which caused the incorrect path to be followed in:dataloader/lib/dataloader/kv.ex
Lines 72 to 80 in 56f7cb4
This prevented new data from being loaded into a
Dataloader.KV
source that contained cached results.The fix proposed here is to use
Map.get/3
with a third argument of:error
, which can be explicitly matched in thecase
statement: