kestra-io / plugin-serdes

https://kestra.io/plugins/plugin-serdes/
Apache License 2.0
2 stars 6 forks source link

Ion to Json task fails when Ion file contains type annotation #138

Open ReLoutre opened 2 months ago

ReLoutre commented 2 months ago

Describe the issue

Using IonToJson task on a file that contains a type annotated value produce infinite nested call of IonSystemLite['loader"] and IonStringLite["system"].

Bug reproduction

Here's a flow to reproduce the error :

id: bug_reproduction
namespace: bloup

inputs:
  - id: test_ref_file
    type: FILE

tasks:
  - id: downgrade_Ion_to_Json
    type: io.kestra.plugin.serdes.json.IonToJson
    from: "{{inputs.test_ref_file}}"

Here's the content of the file to input in the flow :

{someKey:"someValue",attributes:{description:["Some not encoded text"]}}
{someKey:"someValue",attributes:{description:[base64::"TGlzmlhbGUgZGUgbCdJVVQ="]}}
{someKey:"someValue",attributes:{description:["Some not encoded text", "and some more"]}}

Removing the type annotation base64:: works fine.

Expecting behaviour :

While downgrading to JSON type annotation may be totally erased or concerned field may be translated as :

{someKey:"someValue",attributes:{description:[base64::"TGlzmlhbGUgZGUgbCdJVVQ="]}}
->
{"someKey":"someValue","attributes":{"description":[{"annot":"base64","value":"TGlzmlhbGUgZGUgbCdJVVQ="}]}}

For example...

Environment

Error encountered

image

Ben8t commented 2 months ago

Up to implementation, but we could also add a flag to let the user choose the behavior intented (ie. remove annotation metadata from JSON or add a field annotation in the corresponding JSON key-value)

ReLoutre commented 2 months ago

Up to implementation, but we could also add a flag to let the user choose the behavior intented (ie. remove annotation metadata from JSON or add a field annotation in the corresponding JSON key-value)

Being able to do both would indeed be awesome. PS: "annot":"base64" must be "annots":["base64"] instead. Since multiple annotations may be attached to a single value.

loicmathieu commented 2 months ago

It seems to be a bug with the IonMapper, I'll try to create a reproducer to open a bug upstream.

loicmathieu commented 2 months ago

@ReLoutre can you add in a comment the way to generate this base64 annotated field?

ReLoutre commented 2 months ago

In my case I'm using the Java com.amazon.ion.IonWriter class (here's the doc) and use it like following : ionWriter.addTypeAnnotation("base64"); (here's the doc).

ReLoutre commented 2 months ago

PS: Take note that TGlzmlhbGUgZGUgbCdJVVQ= in my example doesn't mean anything in base 64 and may not even be a valid base64 encoding, yet it is solely stored as a string annotated and so it shouldn't have a link with the problem.

ReLoutre commented 2 months ago

In my opinion, the problem is highly related to the following issue.