|
21 | 21 | from ldclient.impl.listeners import Listeners |
22 | 22 | from ldclient.impl.repeating_task import RepeatingTask |
23 | 23 | from ldclient.impl.rwlock import ReadWriteLock |
24 | | -from ldclient.impl.util import ( |
25 | | - _LD_ENVID_HEADER, |
26 | | - _LD_FD_FALLBACK_HEADER, |
27 | | - _Fail, |
28 | | - log |
29 | | -) |
| 24 | +from ldclient.impl.util import _LD_FD_FALLBACK_HEADER, _Fail, log |
30 | 25 | from ldclient.interfaces import ( |
31 | 26 | DataSourceErrorInfo, |
32 | 27 | DataSourceErrorKind, |
@@ -222,8 +217,6 @@ def _run_initializers(self, set_on_ready: Event) -> bool: |
222 | 217 |
|
223 | 218 | if isinstance(basis_result, _Fail): |
224 | 219 | log.warning("Initializer %s failed: %s", initializer.name, basis_result.error) |
225 | | - if basis_result.headers is not None: |
226 | | - self._record_environment_id(basis_result.headers.get(_LD_ENVID_HEADER)) |
227 | 220 | # An error response can still carry the FDv1 fallback directive. |
228 | 221 | if basis_result.headers is not None and \ |
229 | 222 | basis_result.headers.get(_LD_FD_FALLBACK_HEADER) == 'true': |
@@ -422,7 +415,8 @@ def reader(self: 'FDv2'): |
422 | 415 | if self._stop_event.is_set(): |
423 | 416 | return ConditionDirective.FALLBACK |
424 | 417 |
|
425 | | - self._record_environment_id(update.environment_id) |
| 418 | + if update.state == DataSourceState.VALID: |
| 419 | + self._record_environment_id(update.environment_id) |
426 | 420 |
|
427 | 421 | # Handle the update |
428 | 422 | if update.change_set is not None: |
@@ -509,7 +503,7 @@ def _persistent_store_outage_recovery(self, data_store_status: DataStoreStatus): |
509 | 503 | log.error("Failed to reinitialize data store", exc_info=err) |
510 | 504 |
|
511 | 505 | def _record_environment_id(self, environment_id: Optional[str]): |
512 | | - if environment_id is None: |
| 506 | + if not isinstance(environment_id, str) or environment_id == '': |
513 | 507 | return |
514 | 508 |
|
515 | 509 | with self._lock.write(): |
|
0 commit comments