-
Notifications
You must be signed in to change notification settings - Fork 20
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
Conversation
I need to review it, will do it later today. |
There was a problem hiding this 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.
OptimizelySDK/Utils/Validator.cs
Outdated
@@ -103,14 +103,24 @@ public static bool IsFeatureFlagValid(ProjectConfig projectConfig, FeatureFlag f | |||
return true; | |||
} | |||
|
|||
private static Type[] AttributeTypes = |
There was a problem hiding this comment.
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[].
OptimizelySDK/Utils/Validator.cs
Outdated
/// <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()); |
There was a problem hiding this comment.
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.
@mikeng13 Thanks Mike, once Python PR is merged, I will take a look at this PR. |
corrected unit tests IsUserAttributeValid
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
No description provided.