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

fix(api): Only track attributes with valid attribute types. #103

Merged
merged 5 commits into from
Sep 20, 2018

Conversation

mfahadahmed
Copy link
Contributor

No description provided.

@msohailhussain
Copy link
Contributor

I need to review it, will do it later today.

Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msohailhussain I ran the compat tests for this and most of them pass except for this one:

   ✔ Before # features/support/steps.js:35
   ✔ Given the datafile is "ab_experiments.json" # features/support/steps.js:130
   ✔ And 1 "Activate" listener is added # features/support/steps.js:136
   ✔ When activate is called with arguments # features/support/steps.js:201
       """
         experiment_key: ab_running_exp_untargeted
         user_id: test_user_1
         attributes:
           customattr: null
       """
   ✔ Then the result should be "all_traffic_variation" # features/support/steps.js:221
   ✖ And in the response, "listener_called" should match # features/support/steps.js:209
       """
         - experiment_key: ab_running_exp_untargeted
           user_id: test_user_1
           variation_key: all_traffic_variation
           attributes:
             customattr: null
       """
       AssertionError
           + expected - actual

            [
              {
           -    "attributes": {}
           +    "attributes": {
           +      "customattr": [null]
           +    }
                "experiment_key": "ab_running_exp_untargeted"
                "user_id": "test_user_1"
                "variation_key": "all_traffic_variation"
              }

           at World.<anonymous> (/app/features/support/steps.js:211:35)```

Looks like the notification we send to the notification listener doesn't include this `null` attribute value when it should. 

@@ -103,14 +103,24 @@ public static bool IsFeatureFlagValid(ProjectConfig projectConfig, FeatureFlag f
return true;
}

private static Type[] AttributeTypes =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeof generally takes too much time to get the type. Why we just don't replace with attribute types with string[].

/// <summary>
/// Determine if given user attribute is valid.
/// </summary>
/// <param name="attribute">Attribute key and value pair</param>
/// <returns>true if attribute key is not null and value is one of the supported type, false otherwise</returns>
public static bool IsUserAttributeValid(KeyValuePair<string, object> attribute)
{
return !string.IsNullOrEmpty(attribute.Key) && attribute.Value is string || attribute.Value is bool || attribute.Value is int || attribute.Value is double;
return !string.IsNullOrEmpty(attribute.Key) && AttributeTypes.Contains(attribute.Value?.GetType());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.GetType().Name returns string, which we can use.

@msohailhussain
Copy link
Contributor

@mikeng13 Thanks Mike, once Python PR is merged, I will take a look at this PR.

corrected unit tests
IsUserAttributeValid
Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, please fix the nits

@@ -155,16 +155,28 @@ public void TestIsUserAttributeValidWithValidValues()
[Test]
public void TestIsUserAttributeValidWithInvalidValues()
{
var userAttributes = new UserAttributes
var userAttributesInvalid = new UserAttributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Let's call this invalidUserAttributes

[Test]
public void TestIsUserAttributeValidWithEmptyKeyOrValue()
{
var userAttributesValid = new UserAttributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validUserAttributes

[Test]
public void TestIsUserAttributeValidWithInvalidValues()
{
var userAttributesInvalid = new UserAttributes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we call this invalidUserAttributes

@mikeproeng37 mikeproeng37 merged commit 17c7181 into master Sep 20, 2018
@mfahadahmed mfahadahmed deleted the fahad/attribute-validation branch September 27, 2018 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants