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

kcl run --format toml returns wrong data #1792

Open
diefans opened this issue Dec 17, 2024 · 4 comments
Open

kcl run --format toml returns wrong data #1792

diefans opened this issue Dec 17, 2024 · 4 comments
Assignees

Comments

@diefans
Copy link

diefans commented Dec 17, 2024

Bug Report

Using the --format toml option to render TOML instead of YAML returns a wrong result.
Seems like there is a custom/naive toml serializer in place...

1. Minimal reproduce step (Required)

kcl run --format toml /dev/stdin << EOF
schema Bar:

schema Foo:
    b: Bar
    a: str = "a"

Foo {
    b: Bar {}
}
EOF

2. What did you expect to see? (Required)

a = "a"

[b]

3. What did you see instead (Required)

[b]
a = "a"

4. What is your KCL components version? (Required)

kcl version is v0.10.8

@He1pa
Copy link
Contributor

He1pa commented Dec 30, 2024

This is the order defined by schema attr. If you want to achieve what you want, just change the order of a and b.

schema Bar:

schema Foo:
    a: str = "a"
    b: Bar


Foo {
    b: Bar {}
}

I will temporarily close this issue. If you have any questions, please reopen it again.
By the way, as far as I know, the toml file is un-sort

@He1pa He1pa closed this as completed Dec 30, 2024
@diefans
Copy link
Author

diefans commented Dec 30, 2024

The order of the KCL schema def should not matter here, but the order in the TOML matters, since at the moment (with this bug) kcl returns just wrong content by putting a into b but a is a sibling of b and not a child...

a TOML like

[b]
a = "a"

is the follwoing JSON

{
  "b": {
    "a": "a"
  }
}

while a TOML like

a = "a"
[b]

is the following JSON

{
  "a": "a",
  "b": {}
}

...so this issue is not fixed by just changing the order of KCL attributes, this would be unmaintainable if you consider subclassing and it would put the burden of sane serialization to the writer of KCL code.

@diefans
Copy link
Author

diefans commented Dec 30, 2024

@He1pa see https://toml.io/en/v1.0.0#table

Under that, and until the next header or EOF, are the key/values of that table.

@He1pa He1pa reopened this Dec 31, 2024
@He1pa
Copy link
Contributor

He1pa commented Dec 31, 2024

ok, i got you, I will fix it

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

3 participants