Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Conditions continually appended to Switch value #96

Open
pifantastic opened this issue Feb 26, 2015 · 1 comment
Open

Conditions continually appended to Switch value #96

pifantastic opened this issue Feb 26, 2015 · 1 comment

Comments

@pifantastic
Copy link

It's highly possible that I'm just using gargoyle wrong, but I'm experiencing surprising behavior.

In one of my project's apps, I've created a gargoyle.py file:

from __future__ import absolute_import

from gargoyle import gargoyle

gargoyle['foo'].add_condition(
    condition_set='gargoyle.builtins.UserConditionSet(auth.user)',
    field_name='percent',
    condition='0-50'
)

My understanding is that this will make the foo switch active for 50% of users. This seems to work. The value in the database after I run my local server is:

{
  "auth.user": {
    "percent": [
      [
        "i", 
        "0-50"
      ]
    ]
  }
}

But now, if I restart my server, the condition is duplicated:

{
  "auth.user": {
    "percent": [
      [
        "i", 
        "0-50"
      ], 
      [
        "i", 
        "0-50"
      ]
    ]
  }
}

I've traced this to Switch.add_condition:

        if condition not in self.value[namespace][field_name]:
            self.value[namespace][field_name].append((exclude and EXCLUDE or INCLUDE, condition))

Here it's checking if condition which is '0-50' is "in" a list of tuples, which will always return false. Obviously this is solvable by adding commit=False to Switch.add_condition. However, it makes me worry that I'm missing something fundamental.

@pifantastic
Copy link
Author

Also curious if there is documentation for switches somewhere that I'm just missing. http://gargoyle.readthedocs.org/en/latest/ref/conditions.html is empty.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant