Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Make CREATE_MISSING_FLAGS logic universal (#400)" #436

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions waffle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ def get_from_db(cls, name):
objects = cls.objects
if get_setting('READ_FROM_WRITE_DB'):
objects = objects.using(router.db_for_write(cls))

if get_setting('CREATE_MISSING_FLAGS'):
flag, _created = objects.get_or_create(
name=name, defaults={'everyone': get_setting('FLAG_DEFAULT')}
)
return flag

return objects.get(name=name)

@classmethod
Expand Down Expand Up @@ -254,6 +247,16 @@ def is_active(self, request):
log_level = get_setting('LOG_MISSING_FLAGS')
if log_level:
logger.log(log_level, 'Flag %s not found', self.name)
if get_setting('CREATE_MISSING_FLAGS'):
flag, _created = get_waffle_flag_model().objects.get_or_create(
name=self.name,
defaults={
'everyone': get_setting('FLAG_DEFAULT')
}
)
cache = get_cache()
cache.set(self._cache_key(self.name), flag)

return get_setting('FLAG_DEFAULT')

if get_setting('OVERRIDE'):
Expand Down
10 changes: 0 additions & 10 deletions waffle/tests/test_waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,16 +441,6 @@ def test_flag_created_dynamically_default_false(self):
def test_flag_created_dynamically_default_true(self):
self.assert_flag_dynamically_created_with_value(True)

@override_settings(WAFFLE_CREATE_MISSING_FLAGS=True)
@override_settings(WAFFLE_FLAG_DEFAULT=True)
def test_flag_created_dynamically_upon_retrieval(self):
FLAG_NAME = 'myflag'
flag_model = waffle.get_waffle_flag_model()
flag = flag_model.get(FLAG_NAME)

assert flag.is_active(get())
assert flag_model.objects.filter(name=FLAG_NAME).exists()

@mock.patch('waffle.models.logger')
def test_no_logging_missing_flag_by_default(self, mock_logger):
request = get()
Expand Down