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

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

Closed
Kameleoon opened this issue Sep 18, 2024 · 9 comments
Assignees

Comments

@Kameleoon
Copy link

Kameleoon commented Sep 18, 2024

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
@beeme1mr
Copy link
Member

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

@maxveldink
Copy link
Member

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
Copy link
Member

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 maxveldink self-assigned this Sep 23, 2024
@Kameleoon
Copy link
Author

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'

@DmitryAE
Copy link

Hello @maxveldink.

Hope you're well.

Do you have any news? Estimated time?

Thanks!

@maxveldink
Copy link
Member

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
Copy link
Member

@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 🙏🏻

@Kameleoon
Copy link
Author

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.

@maxveldink
Copy link
Member

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

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

No branches or pull requests

4 participants