ch-robinson / dotnet-avro

An Avro implementation for .NET
https://engineering.chrobinson.com/dotnet-avro/
MIT License
136 stars 52 forks source link

Failling to read a schema with a decimal without scale #321

Open pgloria opened 4 days ago

pgloria commented 4 days ago

I've seen in issue #115 that this was already debated and fixed in a previous version. Nevertheless an issue was introduced along the way that prevents the reading of schemas with decimals without scale

Replicated this with the available unit tests, using the following schema: { "type": "bytes", "logicalType": "decimal", "precision": 10 }

I get the following error: Failed Chr.Avro.Representation.Tests.JsonRepresentationTests.SymmetricRepresentations(schema: "{\"type\":\"bytes\",\"logicalType\":\"decimal\",\""...) [1 ms] Error Message: System.InvalidOperationException : Operation is not valid due to the current state of the object. Stack Trace: at System.Text.Json.JsonElement.GetInt32() at Chr.Avro.Representation.JsonDecimalSchemaReaderCase.Read(JsonElement element, JsonSchemaReaderContext context) in /dotnet-avro/src/Chr.Avro.Json/Representation/JsonDecimalSchemaReaderCase.cs:line 47 at Chr.Avro.Representation.JsonSchemaReader.Read(JsonElement element, JsonSchemaReaderContext context) in /dotnet-avro/src/Chr.Avro.Json/Representation/JsonSchemaReader.cs:line 134 at Chr.Avro.Representation.JsonSchemaReader.Read(String schema, JsonSchemaReaderContext context) in /dotnet-avro/src/Chr.Avro.Json/Representation/JsonSchemaReader.cs:line 119 at Chr.Avro.Representation.Tests.JsonRepresentationTests.SymmetricRepresentations(String schema) in /dotnet-avro/tests/Chr.Avro.Json.Tests/JsonRepresentationTests.cs:line 157 at InvokeStub_JsonRepresentationTests.SymmetricRepresentations(Object, Span1) at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) `

pgloria commented 4 days ago

Added a fix + tests in PR #322 Ping me if you need some more details or assistance.