Skip to content

Commit e007dee

Browse files
authored
Merge pull request #10 from PostHog/warn-instead-of-error
Warn instead of error
2 parents d92c398 + 1de9553 commit e007dee

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

posthog/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def shutdown(self):
228228

229229
def _load_feature_flags(self):
230230
if not self.personal_api_key:
231-
raise ValueError('You have to specify a personal_api_key to use feature flags.')
231+
self.log.warning('[FEATURE FLAGS] You have to specify a personal_api_key to use feature flags.')
232+
self.feature_flags = []
233+
return
232234

233235
try:
234236
self.feature_flags = get(self.personal_api_key, '/api/feature_flag/', self.host)['results']
@@ -256,6 +258,8 @@ def feature_enabled(self, key, distinct_id, default=False):
256258
require('distinct_id', distinct_id, ID_TYPES)
257259
error = False
258260

261+
if not self.personal_api_key:
262+
self.log.warning('[FEATURE FLAGS] You have to specify a personal_api_key to use feature flags.')
259263
if not self.feature_flags:
260264
self.load_feature_flags()
261265

posthog/test/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,24 @@ def test_feature_enabled_request(self, patch_get):
274274
}]
275275
self.assertTrue(client.feature_enabled('beta-feature', 'distinct_id'))
276276

277+
@mock.patch('posthog.client.Poller')
277278
@mock.patch('posthog.client.get')
278-
def test_feature_enabled_doesnt_exist(self, patch_get):
279+
def test_feature_enabled_doesnt_exist(self, patch_get, patch_poll):
279280
client = Client(TEST_API_KEY, personal_api_key='test')
280281
client.feature_flags = []
281282

282283
self.assertFalse(client.feature_enabled('doesnt-exist', 'distinct_id'))
283284
self.assertTrue(client.feature_enabled('doesnt-exist', 'distinct_id', True))
284285

286+
@mock.patch('posthog.client.Poller')
287+
@mock.patch('posthog.client.get')
288+
def test_personal_api_key_doesnt_exist(self, patch_get, patch_poll):
289+
client = Client(TEST_API_KEY)
290+
client.feature_flags = []
291+
292+
self.assertFalse(client.feature_enabled('doesnt-exist', 'distinct_id'))
293+
self.assertTrue(client.feature_enabled('doesnt-exist', 'distinct_id', True))
294+
285295
@mock.patch('posthog.client.Poller')
286296
@mock.patch('posthog.client.get')
287297
def test_load_feature_flags_error(self, patch_get, patch_poll):

0 commit comments

Comments
 (0)