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] CelDescriptorsUtil throwing duplicate key exception #351

Closed
2 tasks
atiwari22 opened this issue May 15, 2024 · 4 comments
Closed
2 tasks

[BUG] CelDescriptorsUtil throwing duplicate key exception #351

atiwari22 opened this issue May 15, 2024 · 4 comments

Comments

@atiwari22
Copy link

Describe the bug
CelDescriptorUtil method descriptorCollectionToMap throws duplicate key exception .

As method getFileDescriptorsForDescriptors collect unique Messagetypes for individual filedescriptors but collects all message types for multiple filedescriptors again duplicating message types in the aggregated collection . And when it tries to convert this collection to a map in descriptorCollectionToMap throws duplicate key exception .

To Reproduce
I have a dynamic message with nested message types . As a fix we have collected unique filedescriptor
Check which components this affects:

  • [✅ ] parser
  • checker
  • runtime

Sample expression and input that reproduces the issue:

// sample expression string

Test setup:

// test case in java

Expected behavior
When multiple filedecrptors are provided CelDescriptor should not throw duplicate key exception
Additional context
Add any other context about the problem here.

@l46kok
Copy link
Collaborator

l46kok commented May 16, 2024

Are you trying to leverage the utility class directly or are you running into this issue when evaluating an expression against an environment? If the former, the class is really meant to be used for internal use (it's missing the annotation, we'll mark it as such). If the latter, can you please provide a reproducible test case?

@atiwari22
Copy link
Author

I am not using this utility directly .
CEL works well with typed messages but we are using dynamic messages for Kafka events.

when we directly pass file descriptor of the event message to cel container i.e. single file descriptor it fails to resolves references in expression from different packages , when we pass filedescriptors of each fields in the event message as list of file descriptor cel is able to resolve transitive dependent refrerences from different package .

but now it throws duplicate key references error for wrapper types and other custom messages .

As in CelDescriptorUtils it resolves message type of each file descriptor handling duplicates but creates a single collection resolving all file descriptors and duplicating types across file descriptors and finally throws exception in CelDescriptorUtils.descriptorCollectionMap

Even if we set resolvetypedependency to true we start getting duplicate keys exception.

Handling duplicate key issue in CelDescriptorUtils.descriptorCollectionMap works and fixes all issues and all filters working fine for us.

Example How we are using CEL library

we create Cel cel = CelFactory.standardCelBuilder()
.addVar(eventRef, StructTyoeReference.create(eventMessageDeacriptor.getFullName())).addFileTypes(file descriptor) // this is how we are passing filedescriptors . Explained above
.setOption(CelOptions.current().resolveTypeDependency(false).build()).build();

//then we validate expression
Cel.compile(expression).getAST() // fails for references in expression from different packages.

// then we create program from the syntax tree created above
Cel.createProgram(syntaxTree)

// finally evaluate

program.eval(ImmutableMap.of(eventRef, eventMessage);

our event message is a DynamicMessage which
has nested dynamic messages for all types.

Let me know if you need more information

@l46kok
Copy link
Collaborator

l46kok commented May 20, 2024

It'd help if you could either create a small test project somewhere demonstrating this problem or if you're able to reproduce on your end, feel free to open a PR. I understand where the issue might be happening but without a reproducible test case there's not much I can do.

@l46kok
Copy link
Collaborator

l46kok commented Jun 3, 2024

Please feel free to reopen with a reproducible test case if you're still experiencing this issue.

@l46kok l46kok closed this as completed Jun 3, 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

2 participants