Skip to content

Commit 0f073d0

Browse files
authored
Merge pull request #111 from reddit/move_internal_check_for_dc
Move `_internal` check for DCs prior to call
2 parents 3dfb25b + 1a53e09 commit 0f073d0

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

reddit_decider/__init__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,10 @@ def get_bool(self, feature_name: str, default: bool = False) -> bool:
689689
690690
:return: the boolean value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
691691
"""
692+
if self._internal is None:
693+
logger.error("rs_decider is None--did not initialize.")
694+
return default
695+
692696
return self._get_dynamic_config_value(feature_name, default, bool, self._internal.get_bool)
693697

694698
def get_int(self, feature_name: str, default: int = 0) -> int:
@@ -701,6 +705,10 @@ def get_int(self, feature_name: str, default: int = 0) -> int:
701705
702706
:return: the int value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
703707
"""
708+
if self._internal is None:
709+
logger.error("rs_decider is None--did not initialize.")
710+
return default
711+
704712
return self._get_dynamic_config_value(feature_name, default, int, self._internal.get_int)
705713

706714
def get_float(self, feature_name: str, default: float = 0.0) -> float:
@@ -713,6 +721,10 @@ def get_float(self, feature_name: str, default: float = 0.0) -> float:
713721
714722
:return: the float value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
715723
"""
724+
if self._internal is None:
725+
logger.error("rs_decider is None--did not initialize.")
726+
return default
727+
716728
return self._get_dynamic_config_value(
717729
feature_name, default, float, self._internal.get_float
718730
)
@@ -727,6 +739,10 @@ def get_string(self, feature_name: str, default: str = "") -> str:
727739
728740
:return: the string value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
729741
"""
742+
if self._internal is None:
743+
logger.error("rs_decider is None--did not initialize.")
744+
return default
745+
730746
return self._get_dynamic_config_value(feature_name, default, str, self._internal.get_string)
731747

732748
def get_map(self, feature_name: str, default: Optional[dict] = None) -> Optional[dict]:
@@ -739,6 +755,10 @@ def get_map(self, feature_name: str, default: Optional[dict] = None) -> Optional
739755
740756
:return: the map value of the dyanimc config if it is active/exists, :code:`default` parameter otherwise.
741757
"""
758+
if self._internal is None:
759+
logger.error("rs_decider is None--did not initialize.")
760+
return default
761+
742762
return self._get_dynamic_config_value(feature_name, default, dict, self._internal.get_map)
743763

744764
def get_all_dynamic_configs(self) -> List[Dict[str, Any]]:
@@ -830,10 +850,6 @@ def _get_dynamic_config_value(
830850
dc_type: Type[T],
831851
get_fn: Callable[..., Type[T]],
832852
) -> T:
833-
if self._internal is None:
834-
logger.error("rs_decider is None--did not initialize.")
835-
return default
836-
837853
ctx = self._decider_context.to_dict()
838854

839855
try:

0 commit comments

Comments
 (0)