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

Incorrect number of parameters expected when using IN Query with property injection #2959

Open
timyates opened this issue May 24, 2024 · 4 comments

Comments

@timyates
Copy link
Member

Expected Behavior

Writing an IN @Query with properties injected (such as "SELECT name, '${property.value}' as property_value FROM data WHERE id IN (:id)") should work as with other non-IN queries

Actual Behaviour

We get an exception

java.lang.IllegalStateException: Expandable query parts size should be the same as parameters size + 1. 3 != 1 + 1 SELECT name, 'woo' as property_value FROM data WHERE id IN (?) [SELECT name,  'woo' as property_value FROM data WHERE id IN (, )]
	at io.micronaut.data.runtime.operations.internal.sql.DefaultSqlStoredQuery.<init>(DefaultSqlStoredQuery.java:68)
	at io.micronaut.data.runtime.operations.internal.sql.AbstractSqlRepositoryOperations.decorate(AbstractSqlRepositoryOperations.java:184)
	at io.micronaut.data.runtime.intercept.AbstractQueryInterceptor.findStoreQuery(AbstractQueryInterceptor.java:282)
	at io.micronaut.data.runtime.intercept.AbstractQueryInterceptor.prepareQuery(AbstractQueryInterceptor.java:260)
	at io.micronaut.data.runtime.intercept.AbstractQueryInterceptor.prepareQuery(AbstractQueryInterceptor.java:241)
	at io.micronaut.data.runtime.intercept.AbstractQueryInterceptor.prepareQuery(AbstractQueryInterceptor.java:225)
	at io.micronaut.data.runtime.intercept.DefaultFindAllInterceptor.intercept(DefaultFindAllInterceptor.java:50)
	at io.micronaut.data.runtime.intercept.DefaultFindAllInterceptor.intercept(DefaultFindAllInterceptor.java:35)
	at io.micronaut.data.runtime.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:83)
	at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:138)
	at data.query.parameter.issue.DataRepository$Intercepted.findDataById(Unknown Source)

Steps To Reproduce

Pull the reproducer and run ./gradlew test. The first test fails, but the workaround (using @ParameterExpression) works

Environment Information

OSX, Java 17

Example Application

https://github.com/bloidonia/data-query-parameter-issue/blob/main/src/test/java/data/query/parameter/issue/DataQueryParameterIssueTest.java

Version

4.4.2

@dstepanov
Copy link
Contributor

We don’t support expressions in the queries

@mkimberlin
Copy link
Contributor

@dstepanov Any particular reason? It seems to be at least partially supported, as we are using these property injections in our queries across our application and they only fail to work in this case. Perhaps this lack of support should be documented somewhere? It doesn't seem to be stated in either the javadoc or the guides that I can find.

@timyates
Copy link
Member Author

@dstepanov
Copy link
Contributor

dstepanov commented May 24, 2024

Because for this case, we have to generate the query at the runtime, and to make it easy, we split it into parts at the compilation time, and that breaks the expressions

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

3 participants