MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / map_identity_to_engine

Function map_identity_to_engine

api/util/mappers/engine.py:388–435  ·  view source on GitHub ↗
(
    identity: "Identity",
    *,
    with_overrides: bool = True,
    with_traits: bool = True,
)

Source from the content-addressed store, hash-verified

386
387
388def map_identity_to_engine(
389 identity: "Identity",
390 *,
391 with_overrides: bool = True,
392 with_traits: bool = True,
393) -> IdentityModel:
394 environment_api_key = identity.environment.api_key
395
396 # Read relationships - grab all the data needed from the ORM here.
397 if with_overrides:
398 identity_feature_states: List["FeatureState"] = _get_prioritised_feature_states(
399 identity.identity_features.all(),
400 )
401 multivariate_feature_state_values_by_feature_state_id = {
402 feature_state.pk: feature_state.multivariate_feature_state_values.all()
403 for feature_state in identity_feature_states
404 }
405 else:
406 identity_feature_states = []
407 multivariate_feature_state_values_by_feature_state_id = {}
408
409 identity_traits: Iterable["Trait"] = (
410 identity.identity_traits.all() if with_traits else []
411 )
412
413 # Prepare relationships.
414 identity_feature_state_models = [
415 map_feature_state_to_engine(
416 feature_state,
417 mv_fs_values=multivariate_feature_state_values_by_feature_state_id.pop(
418 feature_state.pk,
419 ),
420 )
421 for feature_state in identity_feature_states
422 ]
423 identity_trait_models = map_traits_to_engine(identity_traits)
424
425 return IdentityModel(
426 # Attributes:
427 identifier=identity.identifier,
428 environment_api_key=environment_api_key,
429 created_date=identity.created_date,
430 django_id=identity.pk,
431 #
432 # Relationships:
433 identity_features=identity_feature_state_models, # type: ignore[arg-type]
434 identity_traits=identity_trait_models,
435 )
436
437
438_rule_type_adapter: TypeAdapter[RuleType] = TypeAdapter(RuleType)

Calls 5

IdentityModelClass · 0.90
map_traits_to_engineFunction · 0.85
allMethod · 0.45

Used in the wild real call sites across dependent graphs

searching dependent graphs…