django-waffle icon indicating copy to clipboard operation
django-waffle copied to clipboard

Cookie is only returned for a testing flag set via GET param if that flag is queried during the request

Open matthewryanscott opened this issue 11 years ago • 3 comments

Given:

  • myflag is set up with testing=True
  • Page A never calls waffle.flag_is_active(request, 'myflag'), and none of the templates it loads have {% flag myflag %}
  • Page B makes that function call, and/or loads a template with that tag.
  • Browser has either dwft_myflag cookie as False, or does not have that cookie.

Then (current behavior):

  • Request page A with GET param ?dwft_myflag=1
  • dwft_myflag cookie is never set to True
  • Request page B without GET param, and myflag is treated as False

Desired behavior:

  • Request page A with GET param ?dwft_myflag=1
  • dwft_myflag cookie is set to True
  • Request page B without GET param, and myflag is treated as True

matthewryanscott avatar May 07 '13 02:05 matthewryanscott

this has bitten me as well

stefanfoulis avatar Jul 19 '14 23:07 stefanfoulis

:+1: a fix for this would be very useful for me too (I wrongly assumed this would be default behaviour)

benje avatar Aug 13 '15 14:08 benje

Honestly, I don't have a good idea of how to fix this. I have a couple of lousy ideas. The problem is that the prefix (dwft_) is user-configurable—in fact it doesn't even have to be a prefix.

Therein lies the problem. So, a couple of things that could work:

  • break backward compat, make it necessarily a prefix
  • do something very gross with regex, like re.compile('^' + test_cookie_template.replace('%s', '(.*)') + '$')

Of those, I'd rather break backward compat.

jsocol avatar May 28 '16 22:05 jsocol