Samples

Samples are on a given percentage of the time. They do not require a request object and can be used in other contexts, such as management commands and tasks.

Warning

Sample values are random: if you check a Sample twice, there is no guarantee you will get the same value both times. If you need to rely on the value more than once, you should store it in a variable.

# YES
foo_on = sample_is_active('foo')
if foo_on:
    pass

# ...later...
if foo_on:
    pass
# NO!
if sample_is_active('foo'):
    pass

# ...later...
if sample_is_active('foo'):  # INDEPENDENT of the previous check
    pass

Sample Attributes

Samples can be administered through the Django admin site or the command line. They have the following attributes:

Name:The name of the Sample.
Percent:A number from 0.0 to 100.0 that determines how often the Sample will be active.
Note:Describe where the Sample is used.

Auto Create Missing

When a sample is evaluated in code that is missing in the database the sample returns the WAFFLE_SAMPLE_DEFAULT value but does not create a sample in the database. If you’d like waffle to create missing samples in the database whenever it encounters a missing sample you can set WAFFLE_CREATE_MISSING_SSAMPLES to True. If WAFFLE_SAMPLE_DEFAULT is True then the Percent attribute of the sample will be created as 100.0 (so that when the sample is checked it always evalues to True). Otherwise the value will be set to 0.0 so that the sample always evaluates to False.

Log Missing

Wether or not you enabled Auto Create Missing Sample, it can be practical to be informed that a sample was or is missing. If you’d like waffle to log a warning, error, … you can set WAFFLE_LOG_MISSING_SAMPLES to any level known by Python default logger.