launchdarkly/erlang-server-sdk

attribute_value type does not permit boolean

Closed this issue · 2 comments

Is this a support request?
No.

Describe the bug
I think that the attribute_value type in src/ldclient_context.erl (line 44) should include boolean() in the type list.

I noticed this when integrating the SDK in an Elixir app and using hammox to mock the LD calls. It picked me up on a flag having a true/false value:

       Value %{attributes: %{"tester" => false}, key: 10, kind: "user"} does not match type :ldclient_context.single_context() | :ldclient_context.multi_context().
         Map value %{"tester" => false} for key :attributes does not match map value type :ldclient_context.attribute_map().
           Map value false for key "tester" does not match map value type :ldclient_context.attribute_value().
             Value false does not match type binary() | integer() | float() | :ldclient_context.attribute_map() | [:ldclient_context.attribute_value()].

I was mocking for a flag rule that was setup like this:

image

When testing against the real LD servers, passing "true" as the attribute value did not work, I needed to use true (ie. a boolean, not a string).

If I changed the bool in the LD web interface to str, then both true and "true" would match the rule. I can use this as a workaround for now.

To reproduce
Create a flag with a rule that is setup "true bool" and test passing a boolean vs a string as the attribute value. It only worked as a boolean value for me. But, the types say boolean is not a valid type.

Expected behavior
Using a boolean as an attribute value in a context passes the type checks.

Logs

     12:34:03.921 request_id=F2PLJHzTBwVrKDoAAAHi [error] ** (Hammox.TypeMatchError) 
     1st argument value %{attributes: %{"tester" => false}, key: 10, kind: "user"} does not match 1st parameter's type :ldclient_context.context().
       Value %{attributes: %{"tester" => false}, key: 10, kind: "user"} does not match type :ldclient_context.single_context() | :ldclient_context.multi_context().
         Map value %{"tester" => false} for key :attributes does not match map value type :ldclient_context.attribute_map().
           Map value false for key "tester" does not match map value type :ldclient_context.attribute_value().
             Value false does not match type binary() | integer() | float() | :ldclient_context.attribute_map() | [:ldclient_context.attribute_value()].
         (hammox 0.7.0) lib/hammox.ex:440: Hammox.check_call/3
         (hammox 0.7.0) lib/hammox.ex:408: Hammox.protected_code/3

SDK version
2.0.2

Language version, developer tools
Elixir 1.14.5
Erlang 25.3.2

OS/platform
MacOS 13.3.1 (a)

Additional context
Add any other context about the problem here.

Hello @lucas-nelson,

Thank you for the report. That looks to be a bug.

Filed internally as 204839

Thanks,
Ryan

Hello @lucas-nelson,

This has been fixed in release 2.0.3.

Thank you!
Ryan