Skip to content

Commit 1087147

Browse files
authored
fix: Read all items when a collection is empty (#524)
1 parent 5d1213e commit 1087147

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎ldclient/impl/integrations/consul/consul_feature_store.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,9 @@ def get_all_internal(self, kind):
8989
# Use the key that each item is stored under, not the key inside the item. A deleted
9090
# item (a "tombstone") is not guaranteed to have a key of its own.
9191
item_key_prefix = self._kind_key(kind) + '/'
92+
# A recursive get returns None, not an empty list, when no key has this prefix.
9293
index, results = self._client.kv.get(self._kind_key(kind), recurse=True)
93-
for result in results:
94+
for result in results or []:
9495
db_key = result['Key']
9596
if not db_key.startswith(item_key_prefix):
9697
continue

‎ldclient/testing/integrations/persistent_feature_store_test_base.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,17 @@ def test_all_reads_tombstone_with_no_key(self, tester):
8585
assert items == {'foo': self.make_feature('foo', 10), 'bar': self.make_feature('bar', 10)}
8686
assert store.get(FEATURES, 'deleted-flag', lambda x: x) is None
8787

88+
def test_all_reads_empty_collection(self, tester):
89+
# A store that holds no items of a kind must read that kind as an empty collection.
90+
# Some database clients report "nothing matched" with a null value rather than an
91+
# empty list.
92+
with self.store(tester) as store:
93+
store.init({FEATURES: {}})
94+
95+
# A second instance reads through to the database instead of its own cache.
96+
with self.store(tester) as other_store:
97+
assert other_store.all(FEATURES, lambda x: x) == {}
98+
8899
def test_stores_with_different_prefixes_are_independent(self):
89100
# This verifies that init(), get(), all(), and upsert() are all correctly using the specified key prefix.
90101
# The delete() method isn't tested separately because it's implemented as a variant of upsert().

0 commit comments

Comments
 (0)