Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segment rules can turn - true > True #129

Closed
dabeeeenster opened this issue Jun 16, 2021 · 1 comment
Closed

Segment rules can turn - true > True #129

dabeeeenster opened this issue Jun 16, 2021 · 1 comment
Assignees
Labels
improvement Improvement to the existing platform

Comments

@dabeeeenster
Copy link
Contributor

Ok, so the reason for this is as follows:

When the FE is creating the segment condition, it silently casts the value to the correct type based on the input and sends this in the json.

e.g. entering 'true' results in the following json:

    "value": true

whereas entering, e.g. 'some string' results in:

    "value": "some string"

The BE simply converts whatever is sent into a string instead (for reasons I explain later in this message), but since the json becomes a python dictionary before storing it in the database, true becomes True. This string value is then what is stored against the segment condition and is what is returned to the FE (hence the discrepancy in what is returned).

When evaluating segments, however, the BE leans on the type of the trait, not the segment condition. So, if the trait is a boolean trait, then the BE will check if the condition value string is a valid python boolean and then compare the trait value against that accordingly. See the (simplified) python logic here:

    def check_boolean_value(self, value: bool) -> bool:
        if self.value in ("True", "true", "1"):
            bool_value = True
        else:
            return False

        if self.operator == EQUAL:
            return value == bool_value
        elif self.operator == NOT_EQUAL:
            return value != bool_value

        return False

Where this logic falls down, which is possibly the issue that the user is having, is when you legitimately want to test a string trait against a value of "true". This will never be possible since the FE will always cast this to a boolean and hence python will store the string "True" instead.

The simple fix here (as far as I can tell) is to prevent the FE from casting these values so that python stores the correct string. The BE will then still evaluate boolean trait values correctly since the logic looks at whether the string value is one of the following:

("True", "true", "1")
@dabeeeenster dabeeeenster added the improvement Improvement to the existing platform label Jun 16, 2021
@kyle-ssg
Copy link
Member

Fixed in f1d420e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Improvement to the existing platform
Projects
None yet
Development

No branches or pull requests

3 participants