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

Feat(typing)/allow non string trait types #43

Conversation

gazreese
Copy link
Collaborator

@gazreese gazreese commented Feb 14, 2024

This fixes #42

Description

  • Remove unnecessary constructors from Trait model
  • Use stringValue instead of value in tests
  • Use traitValue in TraitsEndpoint
  • Test Trait's getters to return strict type of traitValue
  • Pass traitValue to TraitWithIdentity in setTrait() method
  • Add getters to TraitWithIdentity that would return strict type of value (only Int, Double, String, Boolean)
  • Update TraitEntity tests
  • Mark value getter to be deprecated and use traitValue instead
  • Add more variations of mocked responses
  • Add getters that would return strict type of value (only Int, Double, String, Boolean)
  • Rename Trait's value to traitValue and make it type Any, create getter value instead

Type of Change

  • ✨ New feature (non-breaking change which adds functionality)
  • ��️ Bug fix (non-breaking change which fixes an issue)
  • ❌ Breaking change (fix or feature that would cause existing functionality to change)
  • �� Code refactor
  • ✅ Build configuration change
  • �� Documentation
  • ��️ Chore

val identifier: String? = null,
@SerializedName(value = "trait_key") val key: String,
@SerializedName(value = "trait_value") val value: String
)
@SerializedName(value = "trait_value") val traitValue: Any
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this has gone around in a circle a little and now I'm not really sure why the attribute name actually has to change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hi @matthewelwell so because we can define our own getters and constructors the old API for the users should now be exactly the same as it was. They should just get a deprecation warning that they should move to e.g. .stringValue instead.

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

To achieve this we had to move the directly-mapped value property out of the way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This look OK @matthewelwell

Copy link
Contributor

Choose a reason for hiding this comment

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

But why did we need to do this? Could we just have done

@SerializedName(value = "trait_value") val value: Any

... and we'd have been done?

I get that perhaps this is slightly tidier though so I'm happy for the answer to just be "because ugly" 😄

Choose a reason for hiding this comment

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

Hi!

Linus here from Axis, I asked for the fix on this issue. If gazreese would change the type of the value there would be two consequences. My code would stop compiling when I increase the version of the library, and I would have to re-test the behaviour of all my feature flags, since it might change depending on how I set the trait.

In my case I don't have many flags to test, but for customers(api-users) who have been using the sdk for a longer time, the change might be quite tough to do since it might require a lot of testing.

As a user of this sdk I am opting for the deprecation. If you don't find this feedback useful you can just ignore it, I will not take offense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @linusclindgren !

@matthewelwell matthewelwell merged commit b37f1d7 into Flagsmith:main Feb 19, 2024
1 check passed
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.

Trait.trait_value should support non-string types
4 participants