Skip to content

CompositeNodeIdValueSerializer with 2 Guids might generate invalid Id's #8193

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

Open
metalium84 opened this issue Mar 28, 2025 · 1 comment
Open

Comments

@metalium84
Copy link

metalium84 commented Mar 28, 2025

Product

Hot Chocolate

Version

15.1.3

Link to minimal reproduction

https://github.com/metalium84/hc-comp-node-id-serializer-bug.git

Steps to reproduce

  1. Clone the reproduction repository
  2. Run the unit test WithBuggySerializer_FailsSometimes()multiple times until it fails (10 executions should be enough)

What is expected?

I've add a straight-forward implementation of a CompositeNodeIdValueSerializer<CompositeNodeId> whose CompositeNodeId consists of 2 Guid's.
The expectiation is that this implementation can format and parse again any combination of 2 Guid's without errors.

What is actually happening?

For some combinations of 2 Guid's the parsing fails with an error indicating that the formatted id is invalid.
Debugging the CompositeNodeIdValueSerializer<T> base implementation showed that it fails in case the formatting of one of the Guid's contains a byte value which corresponds to the part separator (':'). In this case parsing will fail as the parsing implementation depends on the uniqueness of this separator which is not guaranteed.

I guess there won't be any part separator that for sure won't be produced on formatting the single Guid's. Therefore - as a workaround - I created my custom TryParse() and TryFormatIdPart() implementations which take an additional position argument in order to locate the Guid's properly. It makes the use of a part separator obsolete.
My custom implementation can be found in the AlternativeCompositeNodeIdSerializer class in the reproduction repository. With this implementation, the same unit test always passes.

Relevant log output

Additional context

No response

@michaelstaib
Copy link
Member

The separator must be escaped ... I will have a look why we do not do it in the case of the guid formatting.

@michaelstaib michaelstaib added this to the HC-15.2.0 milestone Mar 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants