Skip to content

Commit 4de4462

Browse files
committed
refactor: Drop _get_store_item dict shim; async stores return decoded objects
The decode was copied from the sync client, where it exists for pre-8.0.0 custom stores that predate the model-object migration. The async SDK is post-8.0.0 with no such legacy: the only async feature store (AsyncInMemoryFeatureStore) decodes on init and returns model objects, and all_flags_state already reads the store without decoding. Evaluate off store.get() directly.
1 parent 1448f4e commit 4de4462

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

ldclient/async_client.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,7 @@
4949
)
5050
from ldclient.migrations import OpTracker, Stage
5151
from ldclient.plugin import EnvironmentMetadata
52-
from ldclient.versioned_data_kind import FEATURES, SEGMENTS, VersionedDataKind
53-
54-
55-
async def _get_store_item(store, kind: VersionedDataKind, key: str) -> Any:
56-
# This decorator around store.get provides backward compatibility with any custom data
57-
# store implementation that might still be returning a dict, instead of our data model
58-
# classes like FeatureFlag.
59-
item = await store.get(kind, key)
60-
return kind.decode(item) if isinstance(item, dict) else item
52+
from ldclient.versioned_data_kind import FEATURES, SEGMENTS
6153

6254

6355
class _NotStartedDataSystem:
@@ -223,10 +215,10 @@ async def variation_eval_fn(key, context):
223215
self.__big_segment_store_manager = big_segment_store_manager
224216

225217
async def get_flag_fn(key):
226-
return await _get_store_item(self._data_system.store, FEATURES, key)
218+
return await self._data_system.store.get(FEATURES, key)
227219

228220
async def get_segment_fn(key):
229-
return await _get_store_item(self._data_system.store, SEGMENTS, key)
221+
return await self._data_system.store.get(SEGMENTS, key)
230222

231223
async def get_membership_fn(key):
232224
return await big_segment_store_manager.get_user_membership(key)
@@ -523,7 +515,7 @@ async def _evaluate_internal(self, key: str, context: Context, default: Any, eve
523515
return EvaluationDetail(default, None, error_reason('USER_NOT_SPECIFIED')), None
524516

525517
try:
526-
flag = await _get_store_item(self._data_system.store, FEATURES, key)
518+
flag = await self._data_system.store.get(FEATURES, key)
527519
except Exception as e:
528520
log.error("Unexpected error while retrieving feature flag \"%s\": %s" % (key, repr(e)))
529521
log.debug(traceback.format_exc())

0 commit comments

Comments
 (0)