cfpb / django-flags

Feature flags for Django projects
https://cfpb.github.io/django-flags/
Creative Commons Zero v1.0 Universal
260 stars 32 forks source link

Allow configurable flag sources #12

Closed willbarton closed 6 years ago

willbarton commented 6 years ago

This change allows us to define FLAG_SOURCES as a dotted list of Python paths to classes that provide a get_flags() method that returns a dictionary of flags names and Condition objects.

FLAG_SOURCES is expected to like this:

FLAG_SOURCES = (
    'flags.sources.SettingsFlagsSource',
    'flags.sources.DatabaseFlagsSource',
)

(These are the defaults to preserve current behavior.)

This should provide some performance improvement when coupled with #11 because database flag conditions will only be queried once per request, no matter how many flags there are.

This opens up potential for supporting sources of flags and conditions that are not just the settings files or the database, and lets someone disable either database or settings flags as a thing entirely.

This change breaks the previous behavior of the FLAG_SOURCES setting and the results of using get_flags(), but neither of these were officially documented. get_flags() is used by Wagtail-Flags, and support for the changes here can be found in https://github.com/cfpb/wagtail-flags/pull/32.

coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 192


Totals Coverage Status
Change from base Build 179: 0.0%
Covered Lines: 856
Relevant Lines: 856

💛 - Coveralls
coveralls commented 6 years ago

Pull Request Test Coverage Report for Build 110


Totals Coverage Status
Change from base Build 107: 0.0%
Covered Lines: 773
Relevant Lines: 773

💛 - Coveralls