@@ -150,6 +150,45 @@ def test_v2_flag_values_evaluate_with_a_fallthrough_reason(tmp_path):
150150 assert detail .reason == {'kind' : 'FALLTHROUGH' }
151151
152152
153+ # ---------------------------------------------------------------------------
154+ # Evaluation before the client counts as initialized
155+ # ---------------------------------------------------------------------------
156+
157+ CACHED_DATA_WARNING = "Feature Flag evaluation attempted before client has initialized - using last known values"
158+
159+
160+ def cached_data_warnings (caplog ) -> List [str ]:
161+ return [r .getMessage () for r in caplog .records if r .getMessage ().startswith (CACHED_DATA_WARNING )]
162+
163+
164+ def test_v1_evaluation_does_not_log_the_cached_data_warning (tmp_path , caplog ):
165+ path = os .path .join (str (tmp_path ), 'data.json' )
166+ write_file (path , DOCUMENT )
167+ config = Config ('SDK_KEY' , update_processor_class = Files .new_data_source (paths = [path ]), send_events = False )
168+ with caplog .at_level (logging .WARNING ), LDClient (config ) as client :
169+ assert client .variation ('flag2' , user , 'default' ) == 'value2'
170+ assert cached_data_warnings (caplog ) == []
171+
172+
173+ @pytest .mark .parametrize ('use_as' , ['initializer' , 'synchronizer' , 'both' ])
174+ def test_v2_evaluation_logs_the_cached_data_warning_once (tmp_path , caplog , use_as ):
175+ # File data has no selector, so the data system reports it as cached, not refreshed.
176+ # The first evaluation then logs the cached data warning, although the value is correct.
177+ path = os .path .join (str (tmp_path ), 'data.json' )
178+ write_file (path , DOCUMENT )
179+ file_source = Files .new_data_source_v2 (paths = [path ])
180+ builder = custom ()
181+ if use_as in ('initializer' , 'both' ):
182+ builder = builder .initializers ([file_source ])
183+ if use_as in ('synchronizer' , 'both' ):
184+ builder = builder .synchronizers (file_source )
185+ config = Config ('SDK_KEY' , datasystem_config = builder .build (), send_events = False )
186+ with caplog .at_level (logging .WARNING ), LDClient (config ) as client :
187+ assert client .variation ('flag2' , user , 'default' ) == 'value2'
188+ assert client .variation ('flag1' , user , 'default' ) == 'on'
189+ assert len (cached_data_warnings (caplog )) == 1
190+
191+
153192# ---------------------------------------------------------------------------
154193# Version fallback
155194# ---------------------------------------------------------------------------
0 commit comments