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

LangChain4JAIServicePortableExtension#processInjectionPoint should treat programmatic lookup differently #27

Closed
manovotn opened this issue Aug 30, 2024 · 11 comments
Assignees
Milestone

Comments

@manovotn
Copy link

Following code is IMO wrong in how it treats programmatic lookup.
One valid type of injection point in CDI is Instance<X>. In this case, the aforementioned code should detect that and based on desired behavior either skip it or perform its logic on the inner X type.

Note that with an Instance<X>, you cannot be sure the user will actually attempt to resolve the X at runtime; instead, they might perform Instance#select() and resolve a subtype instead or not use it at all.

@TheEliteGentleman
Copy link
Collaborator

I've made the change on my branch and created the PR. #28

@manovotn
Copy link
Author

manovotn commented Sep 2, 2024

This issue is based on my conversation with @ehsavoie where the code I linked would sometimes identify the required type as Instance which is wrong. I thought just changing the single method would fix that.
That being said, on closer inspection I can see I was looking into his fork which is slightly behind and the case I am describing was throwing an error where it now only logs. But the same problem should still exist there.

@Emily-Jiang
Copy link
Collaborator

Emily-Jiang commented Sep 2, 2024

Sounds like this issue does not exist in the repo. Shall we close this here @manovotn ?

@manovotn
Copy link
Author

manovotn commented Sep 2, 2024

@Emily-Jiang Sorry I am not very familiar with this code base (or rather, not at all :)) but while my initial assumption was wrong, the code still looks a but weird.
For instance this part:

if (Instance.class.equals(Reflections.getRawType(event.getInjectionPoint().getType()))) {
   processInjectionPoint(event);
}

The event.getInjectionPoint().getEvent() should never return Instance. According to the javadoc of InjectionPoint:

If the injection point is a dynamically selected reference obtained then the metadata obtain reflects the injection point of
the {@link Instance}, with the required type and any additional required qualifiers defined by {@linkplain Instance
Instance.select()}.

@Emily-Jiang
Copy link
Collaborator

@Emily-Jiang Sorry I am not very familiar with this code base (or rather, not at all :)) but while my initial assumption was wrong, the code still looks a but weird. For instance this part:

if (Instance.class.equals(Reflections.getRawType(event.getInjectionPoint().getType()))) {
   processInjectionPoint(event);
}

The event.getInjectionPoint().getEvent() should never return Instance. According to the javadoc of InjectionPoint:

If the injection point is a dynamically selected reference obtained then the metadata obtain reflects the injection point of
the {@link Instance}, with the required type and any additional required qualifiers defined by {@linkplain Instance
Instance.select()}.

Fair point @manovotn ! The processInjectionPoint(event) would never be executed.

@TheEliteGentleman
Copy link
Collaborator

This PR should resolve this.

@Emily-Jiang Sorry I am not very familiar with this code base (or rather, not at all :)) but while my initial assumption was wrong, the code still looks a but weird. For instance this part:

if (Instance.class.equals(Reflections.getRawType(event.getInjectionPoint().getType()))) {
   processInjectionPoint(event);
}

The event.getInjectionPoint().getEvent() should never return Instance. According to the javadoc of InjectionPoint:

If the injection point is a dynamically selected reference obtained then the metadata obtain reflects the injection point of
the {@link Instance}, with the required type and any additional required qualifiers defined by {@linkplain Instance
Instance.select()}.

Fair point @manovotn ! The processInjectionPoint(event) would never be executed.

@TheEliteGentleman
Copy link
Collaborator

@manovotn unfortunately the Instance if-statement is true, but we need to process it based on its parameterized type. I've updated the CDI Extension and simplified the whole process entirely.

@manovotn
Copy link
Author

manovotn commented Sep 5, 2024

@manovotn unfortunately the Instance if-statement is true, but we need to process it based on its parameterized type. I've updated the CDI Extension and simplified the whole process entirely.

Ok, I stand corrected...and confused :)
I wrote a quick test for this in Weld (code) and you are right - it indeed returns Instance<X> as a type so your code against current spec/Weld version is correct.

Now, I am not sure if this is intended behavior or a bug - it is in fact more practical this way as it allows you to observe dynamic resolution injection points explicitly but the specification doesn't seem to have much ground for it apart from saying that:

getInjectionPoint() returns the InjectionPoint object that will be used by the container to perform injection.

@manovotn
Copy link
Author

manovotn commented Sep 5, 2024

FTR, I have created a specification clarification issue which you can find under jakartaee/cdi#826

@TheEliteGentleman
Copy link
Collaborator

Closing this as we've discovered that this is a non-issue and code has been merged to the main branch.

@TheEliteGentleman TheEliteGentleman self-assigned this Sep 26, 2024
@ehsavoie ehsavoie added this to the 1.0.0-Alpha1 milestone Oct 11, 2024
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