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] Expression compilation failure for expressions involving fields which are imported from proto files in different module #118

Open
iambharaths opened this issue Mar 25, 2024 · 0 comments
Labels
Bug Something isn't working

Comments

@iambharaths
Copy link

Description

The project i am working is a multi module one, there are fields in a proto for which i am trying to validations that has fields imported from the common module.

The project structure is as given below

└── common
    └── src
        └── main
            └── java
                └── com
                    └── iambharaths
                        └── common
                            └── pax.proto
└── offer
    └── src
        └── main
            └── java
                └── com
                    └── iambharaths
                        └── offer
                            └── shopping_rq.proto

The structure of the shopping_rq.proto file is as given below for which the above error is being thrown.

syntax = "proto3";
package iambharaths.offer;

import "google/api/field_behavior.proto";

import "iambharaths/common/pax.proto";

option java_package = "iambharaths.offer";
option java_outer_classname = "ShoppingRqProto";
option java_multiple_files = true;

message ShoppingRQ {
  string origin_station_code = 1 [(google.api.field_behavior) = REQUIRED,
    (buf.validate.field).required = true];
  string dest_station_code = 2 [(google.api.field_behavior) = REQUIRED,
    (buf.validate.field).required = true];
  string onward_dep_date = 3 [(google.api.field_behavior) = REQUIRED,
    (buf.validate.field).required = true];
  string return_dep_date = 4 [(google.api.field_behavior) = REQUIRED,
    (buf.validate.field).required = true];
  map<string, iambharaths.common.Pax> passengers = 5 [(buf.validate.field).map.max_pairs = 9, (buf.validate.field).map.min_pairs = 1];
  option (buf.validate.message).cel = {
    id: "at_least_one_adt_pax",
    message: "there must be at least one adult",
    expression: "this.passengers.exists(paxId, this.passengers[paxId].ptc == 1)"
  };
}

When trying to validate the ShoppingRQ message using the validator.validate() method i keep getting this error

build.buf.protovalidate.exceptions.CompilationException: Failed to compile expression at_least_one_adt_pax:
ERROR: :1:53: [internal] unexpected failed resolution of 'iambharaths.common.Pax'

Expected Behavior

The validation should be successful without any CompilationException being thrown.

Actual Behavior

The message validation fails with build.buf.protovalidate.exceptions.CompilationException being thrown.

Screenshots/Logs

build.buf.protovalidate.exceptions.CompilationException: Failed to compile expression at_least_one_adt_pax:
ERROR: <input>:1:53: [internal] unexpected failed resolution of 'iambharaths.common.Pax'
 | this.passengers.exists(paxId, this.passengers[paxId].ptc == 1)
 | ....................................................^
	at build.buf.protovalidate.internal.expression.AstExpression.newAstExpression(AstExpression.java:49)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder$DescriptorCacheBuilder.compileConstraints(EvaluatorBuilder.java:525)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder$DescriptorCacheBuilder.processMessageExpressions(EvaluatorBuilder.java:200)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder$DescriptorCacheBuilder.buildMessage(EvaluatorBuilder.java:176)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder$DescriptorCacheBuilder.createMessageEvaluator(EvaluatorBuilder.java:159)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder$DescriptorCacheBuilder.build(EvaluatorBuilder.java:148)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder.build(EvaluatorBuilder.java:112)
	at build.buf.protovalidate.internal.evaluator.EvaluatorBuilder.load(EvaluatorBuilder.java:91)
	at build.buf.protovalidate.Validator.validate(Validator.java:76)
	at com.github.iambharaths.offermanagement.validation.RequestValidator.validateRequest(RequestValidator.java:21)
	at com.github.iambharaths.offermanagement.api.OfferManagementV4Api.shop(OfferManagementV4Api.java:55)
	at com.github.iambharaths.offermanagement.api.OfferManagementV4Api$$FastClassBySpringCGLIB$$3a57c4dd.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:783)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
	at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:49)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:58)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
	at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698)
	at com.github.iambharaths.offermanagement.api.OfferManagementV4Api$$EnhancerBySpringCGLIB$$58b63b3a.shop(<generated>)
	at com.github.iambharaths.offer.OfferManagementServiceGrpc$MethodHandlers.invoke(OfferManagementServiceGrpc.java:1044)
	at io.grpc.stub.ServerCalls$UnaryServerCallHandler$UnaryServerCallListener.onHalfClose(ServerCalls.java:182)
	at io.grpc.PartialForwardingServerCallListener.onHalfClose(PartialForwardingServerCallListener.java:35)
	at io.grpc.ForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:23)
	at io.grpc.ForwardingServerCallListener$SimpleForwardingServerCallListener.onHalfClose(ForwardingServerCallListener.java:40)
	at io.grpc.Contexts$ContextualizedServerCallListener.onHalfClose(Contexts.java:86)
	at io.grpc.internal.ServerCallImpl$ServerStreamListenerImpl.halfClosed(ServerCallImpl.java:351)
	at io.grpc.internal.ServerImpl$JumpToApplicationThreadServerStreamListener$1HalfClosed.runInContext(ServerImpl.java:861)
	at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
	at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.lang.Thread.run(Thread.java:833)

Environment

  • Operating System: macOS
  • Version: macOS 14.4
  • Protobuf Compiler & Version: protoc 3.24.4
  • Protovalidate Version: v0.2.0
@iambharaths iambharaths added the Bug Something isn't working label Mar 25, 2024
@iambharaths iambharaths changed the title [BUG] Expression compilation failure when for expressions involving fields which are imported from proto files in different module [BUG] Expression compilation failure for expressions involving fields which are imported from proto files in different module Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant