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

bug: Cannot run Groovy Script functions as a REST service since core 4.3.0 #10580

Closed
timyates opened this issue Mar 6, 2024 · 7 comments · Fixed by micronaut-projects/micronaut-groovy#586
Assignees
Labels
lang: groovy Issues or features specific to Groovy type: bug Something isn't working

Comments

@timyates
Copy link
Contributor

timyates commented Mar 6, 2024

Issue description

The upgrade to core 4.3.0 seems to have broken running groovy scripts as Functions as REST services

Reproducer

Check out master of micronaut-groovy, and run:

./gradlew :micronaut-function-groovy:test --tests FunctionTransformSpec

The 4 REST tests will fail

If we switch micronaut-core back to 4.2.4 then the tests pass...

Suspicions

I suspect what is happening is the Bean definition is getting written BEFORE the AST transformation is occuring.

This means that in the class $NotifyWithArgsFunction$Definition$Reference.class with 4.3.x we get $ANNOTATION_METADATA set to

$ANNOTATION_METADATA = AnnotationMetadata.EMPTY_METADATA;

Wheras with micronaut 4.2.4, it is:

$ANNOTATION_METADATA = new DefaultAnnotationMetadata(Map.of("io.micronaut.function.FunctionBean", Map.of("method", "send", "value", "notify-with-args")), Map.of("io.micronaut.context.annotation.Executable", Map.of("processOnStartup", false), "io.micronaut.core.annotation.EntryPoint", Map.of(), "jakarta.inject.Named", Map.of("value", "notify-with-args"), "jakarta.inject.Qualifier", Map.of(), "jakarta.inject.Scope", Map.of(), "jakarta.inject.Singleton", Map.of(), "java.lang.annotation.Annotation", Map.of("name", "notify-with-args")), Map.of("io.micronaut.context.annotation.Executable", Map.of("processOnStartup", false), "io.micronaut.core.annotation.EntryPoint", Map.of(), "jakarta.inject.Named", Map.of("value", "notify-with-args"), "jakarta.inject.Qualifier", Map.of(), "jakarta.inject.Scope", Map.of(), "jakarta.inject.Singleton", Map.of(), "java.lang.annotation.Annotation", Map.of("name", "notify-with-args")), Map.of("io.micronaut.function.FunctionBean", Map.of("method", "send", "value", "notify-with-args")), Map.of("io.micronaut.context.annotation.Executable", List.of("io.micronaut.function.FunctionBean"), "io.micronaut.core.annotation.EntryPoint", List.of("io.micronaut.function.FunctionBean"), "jakarta.inject.Named", List.of("io.micronaut.function.FunctionBean"), "jakarta.inject.Qualifier", List.of("jakarta.inject.Named"), "jakarta.inject.Scope", List.of("jakarta.inject.Singleton"), "jakarta.inject.Singleton", List.of("io.micronaut.function.FunctionBean"), "java.lang.annotation.Annotation", List.of("io.micronaut.function.FunctionBean")), false, false);
@timyates timyates added type: bug Something isn't working lang: groovy Issues or features specific to Groovy labels Mar 6, 2024
@timyates
Copy link
Contributor Author

timyates commented Mar 6, 2024

Could it be that both TypeElementVisitorTransform and FunctionTransform in micronaut-groovy both use CompilePhase.SEMANTIC_ANALYSIS, and there's no guarantee of order for AST transformations in the same Phase?

@dstepanov
Copy link
Contributor

I don't know much about Groovy, but you can try to find what changed vs. the version that worked.

@wetted
Copy link
Contributor

wetted commented Mar 6, 2024

Thanks for opening this issue @timyates. This is a blocker for four PRs I am trying to resolve for micronaut-groovy.

wetted added a commit to micronaut-projects/micronaut-groovy that referenced this issue Mar 7, 2024
wetted added a commit to micronaut-projects/micronaut-groovy that referenced this issue Mar 7, 2024
#531)

* fix(deps): update dependency io.micronaut:micronaut-core-bom to v4.3.9

* Disable tests pending fix to micronaut-projects/micronaut-core#10580

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dean Wette <wetted@unityfoundation.io>
@timyates
Copy link
Contributor Author

timyates commented Mar 7, 2024

I don't know much about Groovy, but you can try to find what changed vs. the version that worked.

It currently makes no sense... It seems to work with core afdc5e835feff99bb9c65c2972f8b0029ec3294e

But fails with the next commit...fa244031e612d75b3994146e31e177e1ff1734e2

All that changes is the version property... I suspect something else is going on...

@paulk-asert
Copy link
Contributor

I don't know if transform order is the problem, but in Groovy 4+, if a transform implements TransformWithPriority, you can override the processing order of transforms within the same phase by setting a priority. They are run in order of source code appearance if in the same phase with the same priority. The transformation with the highest positive priority will be processed first. Negative priorities will be processed after all transformations with a priority of zero (the default).

@timyates
Copy link
Contributor Author

timyates commented Mar 27, 2024

I must be wrong and something else must be causing the problem...

I updated the FunctionTransform to implement TransformWithPriority and return a priority of 1, and the issue remains

Back to confused for me ;-)

@sdelamo sdelamo removed this from 4.3.8 Release Apr 16, 2024
@sdelamo sdelamo added type: regression A breaking change was introduced in a minor or patch release and removed type: regression A breaking change was introduced in a minor or patch release labels Apr 16, 2024
@sdelamo sdelamo removed this from 4.4.1 Release Apr 22, 2024
@sdelamo sdelamo removed this from 4.4.2 Release May 3, 2024
@dstepanov
Copy link
Contributor

@paulk-asert That is not working. I have debuged the code and the call in ASTTransformationVisitor#addPhaseOperationsForGlobalTransforms never sorts ASTTransformation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang: groovy Issues or features specific to Groovy type: bug Something isn't working
Projects
No open projects
Status: No status
Development

Successfully merging a pull request may close this issue.

6 participants