liveBook · Manning

Waffle Sample

As explained in Django in Action

A Waffle Sample is a Django Waffle feature control that enables a feature for a configured percentage of visitors.

A Waffle Sample limits a new feature to a percentage of visitors. Wrap the feature in a conditional block, then let Django Waffle decide whether each call is active. This provides a small production audience for beta testing without exposing unfinished code to everyone. section 13.4

Use a Sample through this request flow:

  • Install Django Waffle with `python -m pip install django-waffle`. section 13.4
  • Add `waffle` to `INSTALLED_APPS`, add `waffle.middleware.WaffleMiddleware` to `MIDDLEWARE`, and run migrations for Waffle’s database tables. section 13.4
  • Create a Sample in Django Admin and set its active percentage. section 13.4
  • Call `sample_is_active()` with the Sample name and use its Boolean result to choose whether the feature runs. section 13.4
  • Store the result when one view needs a consistent decision, because later calls generate a new random value. section 13.4

A sampled feature

Suppose a RiffMates view contains a new beta feature. Create a Sample configured for a percentage of visitors, then evaluate `sample_is_active("new-riff-feature")`. If it returns true, render the beta feature; otherwise, continue with the existing view behavior. Save that Boolean if the view checks the Sample more than once. section 13.4

How Django in Action covers it

How deep it goes
Explains installation, configuration, Admin setup, Boolean evaluation, and repeated-call randomness.
Examples
Uses Django Admin configuration and conditional code guarded by sample_is_active().
What it assumes
Assumes a Django application and teaches Waffle installation, middleware, migrations, and Sample evaluation.
What you can do after
Apply it via Django Waffle to beta-test a feature with a selected visitor percentage.
How it connects
Connects feature flags with Django Waffle switches and flags.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.