ruby-sdk icon indicating copy to clipboard operation
ruby-sdk copied to clipboard

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK

Open Kameleoon opened this issue 1 year ago • 7 comments

Hello guys!

In the latest version (0.4.0), the fetch_{result_type}_{suffix} evaluation methods are not functioning as expected. This issue appears to stem from a call to an undefined method evaluation_context in the OpenFeature::SDK. Below is the problematic code:

def fetch_#{result_type}_#{suffix}(flag_key:, default_value:, evaluation_context: nil)
  built_context = EvaluationContextBuilder.new.call(api_context: OpenFeature::SDK.evaluation_context, client_context: self.evaluation_context, invocation_context: evaluation_context)
  resolution_details = @provider.fetch_#{result_type}_value(flag_key:, default_value:, evaluation_context: built_context). 
  evaluation_details = EvaluationDetails.new(flag_key:, resolution_details:)
  #{"evaluation_details.value" if suffix == :value}
end

There is a problematic line in the code:

built_context = EvaluationContextBuilder.new.call(api_context: OpenFeature::SDK.evaluation_context, client_context: self.evaluation_context, invocation_context: evaluation_context)

Any call to fetch_{result_type}_{suffix} throws the following error:

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK

Kameleoon avatar Sep 18 '24 16:09 Kameleoon

Hey @maxveldink, is this something you could help with?

beeme1mr avatar Sep 18 '24 19:09 beeme1mr

Sure! I've got an idea to expand that section out anyway and remove that metaprogramming. I'll clean it up tomorrow morning if I've got some time, and when I'm back from vacation Monday if not.

maxveldink avatar Sep 18 '24 22:09 maxveldink

Apologies for the delay here; I'm taking a look this morning. I'm not able to replicate this locally loading the gem in a console and my projects utilizing OF don't appear to have this issue. That method is being appropriately forwarded to the API instance. Do you have a snippet of calling code which is triggering this?

Related to this issue, I do plan on expanding this metaprogramming out so it's clearer and tooling can better analyze the eval methods. That could eliminate this issue as well, or help us pinpoint it.

maxveldink avatar Sep 23 '24 09:09 maxveldink

Hello @maxveldink

Do you have a snippet of calling code which is triggering this?

    client = OpenFeature::SDK::API.instance.build_client
    evaluation_details = client.fetch_string_details(flag_key: feature_key, default_value: 'test',
                                                     evaluation_context: eval_context)

throws:

NoMethodError: undefined method `evaluation_context' for module OpenFeature::SDK
    /opt/homebrew/lib/ruby/gems/3.3.0/gems/openfeature-sdk-0.4.0/lib/open_feature/sdk/client.rb:29:in `fetch_string_details'

Kameleoon avatar Sep 23 '24 13:09 Kameleoon

Hello @maxveldink.

Hope you're well.

Do you have any news? Estimated time?

Thanks!

DmitryAE avatar Sep 30 '24 06:09 DmitryAE

Yes, sorry for the delay; I'll be working on this tomorrow (I think I've got the under lying reason) and will cut a release once that's approved.

maxveldink avatar Sep 30 '24 10:09 maxveldink

@Kameleoon I've been playing around with this issue tonight, and I'm unable to replicate that problem locally on main. Your snippet was helpful, but I'm seeing a successful evaluation there.

One thing I noticed was you're creating the client through the singleton instance method; the primary entrypoint should be OpenFeature::SDK.build_client (but I don't see how that would cause this problem, but would be worth a shot).

I've been meaning to refactor away from metaprogramming here in favor of explicit method defs, so I've created a draft to do that at #154. Could you also build off of that branch and see if you're seeing the same issue?

@Kameleoon can you provide any more context around how you're initializing OF in your project, or a wider code snippet? @DmitryAE I wonder if you could provide a code snippet/context as well.

Thank you 🙏🏻

maxveldink avatar Oct 02 '24 00:10 maxveldink

Hello @maxveldink

I hope you're doing well.

I want to sincerely apologize for the delayed response. After applying your suggestion to call methods without API.instance, we identified an issue on our end with how we imported the OpenFeature SDK. We mistakenly imported open_feature/sdk/api, which was necessary due to our use of API.instance (as we thought), and this turned out to be the root cause.

We deeply regret any inconvenience this may have caused you. Your guidance was invaluable, and we greatly appreciate your support throughout this process.

Thank you once again for your help!

Best regards, The Kameleoon Team

P.S. Please disregard the message from @DmitryAE, which is the personal account of one of our developers. It pertained to the same issue.

Kameleoon avatar Oct 15 '24 14:10 Kameleoon

Glad that we got it solved! Reach out if you have any other issues with the SDK!

maxveldink avatar Oct 16 '24 00:10 maxveldink