6
6
import pydantic
7
7
import requests
8
8
from flag_engine import engine
9
+ from flag_engine .context .mappers import map_environment_identity_to_context
9
10
from flag_engine .environments .models import EnvironmentModel
10
11
from flag_engine .identities .models import IdentityModel
11
12
from flag_engine .identities .traits .models import TraitModel
12
13
from flag_engine .identities .traits .types import TraitValue
13
- from flag_engine .segments .evaluator import get_identity_segments
14
14
from requests .adapters import HTTPAdapter
15
15
from requests .utils import default_user_agent
16
16
from urllib3 import Retry
@@ -280,10 +280,18 @@ def get_identity_segments(
280
280
281
281
traits = traits or {}
282
282
identity_model = self ._get_identity_model (identifier , ** traits )
283
- segment_models = get_identity_segments (
284
- environment = self ._environment , identity = identity_model
283
+ context = map_environment_identity_to_context (
284
+ environment = self ._environment ,
285
+ identity = identity_model ,
286
+ override_traits = None ,
285
287
)
286
- return [Segment (id = sm .id , name = sm .name ) for sm in segment_models ]
288
+ evaluation_result = engine .get_evaluation_result (
289
+ context = context ,
290
+ )
291
+ return [
292
+ Segment (id = int (sm ["key" ]), name = sm ["name" ])
293
+ for sm in evaluation_result .get ("segments" , [])
294
+ ]
287
295
288
296
def update_environment (self ) -> None :
289
297
try :
@@ -321,8 +329,18 @@ def _get_environment_from_api(self) -> EnvironmentModel:
321
329
def _get_environment_flags_from_document (self ) -> Flags :
322
330
if self ._environment is None :
323
331
raise TypeError ("No environment present" )
324
- return Flags .from_feature_state_models (
325
- feature_states = engine .get_environment_feature_states (self ._environment ),
332
+ identity = self ._get_identity_model (identifier = "" , traits = None )
333
+
334
+ context = map_environment_identity_to_context (
335
+ environment = self ._environment ,
336
+ identity = identity ,
337
+ override_traits = None ,
338
+ )
339
+
340
+ evaluation_result = engine .get_evaluation_result (context = context )
341
+
342
+ return Flags .from_evaluation_result (
343
+ evaluation_result = evaluation_result ,
326
344
analytics_processor = self ._analytics_processor ,
327
345
default_flag_handler = self .default_flag_handler ,
328
346
)
@@ -333,13 +351,20 @@ def _get_identity_flags_from_document(
333
351
identity_model = self ._get_identity_model (identifier , ** traits )
334
352
if self ._environment is None :
335
353
raise TypeError ("No environment present" )
336
- feature_states = engine .get_identity_feature_states (
337
- self ._environment , identity_model
354
+
355
+ context = map_environment_identity_to_context (
356
+ environment = self ._environment ,
357
+ identity = identity_model ,
358
+ override_traits = None ,
338
359
)
339
- return Flags .from_feature_state_models (
340
- feature_states = feature_states ,
360
+
361
+ evaluation_result = engine .get_evaluation_result (
362
+ context = context ,
363
+ )
364
+
365
+ return Flags .from_evaluation_result (
366
+ evaluation_result = evaluation_result ,
341
367
analytics_processor = self ._analytics_processor ,
342
- identity_id = identity_model .composite_key ,
343
368
default_flag_handler = self .default_flag_handler ,
344
369
)
345
370
0 commit comments