-
Notifications
You must be signed in to change notification settings - Fork 18
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
IllegalArgumentException: FieldDescriptor does not match message type
when using protobuf.Any
#295
Comments
This TODO may be relevant:
|
So it appears there's actually two issues:
The workaround for the (1) is to manually check against a list of known types. I don't know of any way to reflectively determine these types at the moment. The workaround for (2) is to unpack any Example: message Container {
int64 foo = 1;
message Contained {
google.protobuf.Any metadata = 1;
}
Contained contained = 2;
} message TestMetadata {
uint32 age = 1;
} val actualMessage: Container = // Initialized with contained.metadata set to a TestMetadata.
val typeRegistry: TypeRegistry = // Initialized with known Descriptors
val env =
Env.newEnv(
EnvOption.container("Container"),
EnvOption.customTypeProvider(celTypeRegistry),
EnvOption.customTypeAdapter(celTypeRegistry),
EnvOption.declarations(Decls.newVar("foo", Checked.checkedInt), Decls.newVar("contained.metadata", Checked.checkedAny))
)
val ast = env.compile("contained.metadata.age > 21").ast
val program = env.program(ast)
val variables: Map<String, Any> = mutableMapOf<String, Any>().apply {
for ((fieldDescriptor, value) in actualMessage.allFields) {
put(fieldDescriptor.name, value)
}
put("contained.metadata", DynamicMessage.parseFrom(typeRegistry.getDescriptorForTypeUrl(actualMessage.contained.metadata.typeUrl), actualMessage.contained.metadata.value))
} |
@SanjayVas : Thanks for the detailed analysis! We'll see what can be done. Still, if you have a particular fix in mind please feel free to open a PR. |
I get the following error when my var is a
protobuf.Any
message:Stack trace:
cel-java version: 0.3.11
Using a debugger at
FieldDescription.getValueFromField
, it appears thatmessage
is an instance ofDynamicMessage
withtype.fullName
equal togoogle.protobuf.Any
. This has the correct type URL set. TheFieldDescriptor
hascontainingType.fullName
equal to the concrete message type that the type URL resolves to.I imagine that something is going wrong in unpacking. I've specified the message type in EnvOptions using a
DynamicMessage
from aDescriptor
which was built from aFileDecriptorSet
. In my test scenario, that message type also happens to be compiled in.The text was updated successfully, but these errors were encountered: