Skip to content

Commit 29555eb

Browse files
authored
Fix initial config load when auto poll enabled with results from cache (#63)
1 parent 3c2d2bb commit 29555eb

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

configcatclient/configservice.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def __init__(self, sdk_key, polling_mode, hooks, config_fetcher, log, config_cac
3232
self._set_initialized()
3333

3434
def get_config(self):
35+
threshold = utils.distant_past
36+
prefer_cached = self._initialized.is_set()
3537
if isinstance(self._polling_mode, LazyLoadingMode):
36-
entry, _ = self._fetch_if_older(
37-
utils.get_utc_now_seconds_since_epoch() - self._polling_mode.cache_refresh_interval_seconds)
38-
return (entry.config, entry.fetch_time) \
39-
if not entry.is_empty() \
40-
else (None, utils.distant_past)
38+
threshold = utils.get_utc_now_seconds_since_epoch() - self._polling_mode.cache_refresh_interval_seconds
39+
prefer_cached = False
4140
elif isinstance(self._polling_mode, AutoPollingMode) and not self._initialized.is_set():
4241
elapsed_time = (utils.get_utc_now() - self._start_time).total_seconds()
42+
threshold = utils.get_utc_now_seconds_since_epoch() - self._polling_mode.poll_interval_seconds
4343
if elapsed_time < self._polling_mode.max_init_wait_time_seconds:
4444
self._initialized.wait(self._polling_mode.max_init_wait_time_seconds - elapsed_time)
4545

@@ -51,7 +51,7 @@ def get_config(self):
5151
else (None, utils.distant_past)
5252

5353
# If we are initialized, we prefer the cached results
54-
entry, _ = self._fetch_if_older(utils.distant_past, prefer_cache=self._initialized.is_set())
54+
entry, _ = self._fetch_if_older(threshold, prefer_cached=prefer_cached)
5555
return (entry.config, entry.fetch_time) \
5656
if not entry.is_empty() \
5757
else (None, utils.distant_past)
@@ -98,7 +98,7 @@ def close(self):
9898
if isinstance(self._polling_mode, AutoPollingMode):
9999
self._stopped.set()
100100

101-
def _fetch_if_older(self, threshold, prefer_cache=False):
101+
def _fetch_if_older(self, threshold, prefer_cached=False):
102102
"""
103103
:return: Returns the ConfigEntry object and error message in case of any error.
104104
"""
@@ -116,7 +116,7 @@ def _fetch_if_older(self, threshold, prefer_cache=False):
116116
return self._cached_entry, None
117117

118118
# If we are in offline mode or the caller prefers cached values, do not initiate fetch.
119-
if self._is_offline or prefer_cache:
119+
if self._is_offline or prefer_cached:
120120
return self._cached_entry, None
121121

122122
# No fetch is running, initiate a new one.

configcatclient/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CONFIGCATCLIENT_VERSION = "9.0.3"
1+
CONFIGCATCLIENT_VERSION = "9.0.4"

configcatclienttests/test_rollout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ def test_attribute_conversion_to_canonical_string(self, key, custom_attribute_va
418418
])
419419
def test_comparison_attribute_trimming(self, key, expected_return_value):
420420
config = LocalFileDataSource(path.join(self.script_dir, 'data/comparison_attribute_trimming.json'),
421-
OverrideBehaviour.LocalOnly, None).get_overrides()
421+
OverrideBehaviour.LocalOnly, None).get_overrides()
422422

423423
log = Logger('configcat', Hooks())
424424
logger = logging.getLogger('configcat')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def parse_requirements(filename):
66
return [line for line in lines if line]
77

88

9-
configcatclient_version = '9.0.3'
9+
configcatclient_version = '9.0.4'
1010

1111
requirements = parse_requirements('requirements.txt')
1212

0 commit comments

Comments
 (0)