Skip to content

Variable override does not work #232

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
legal90 opened this issue May 9, 2025 · 5 comments
Open

Variable override does not work #232

legal90 opened this issue May 9, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@legal90
Copy link

legal90 commented May 9, 2025

Bug Report

1. Minimal reproduce step (Required)

Example from the official doc:
https://www.kcl-lang.io/docs/reference/lang/tour#kcl-cli-variable-override

schema Person:
    name: str
    age: int
    ids?: [int]

person = Person {
    name = "Alice"
    age = 10
}

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

With a string and integer values

kcl main.k -O :person.name=\"Bob\" -O :person.age=10

Expected Output:

person:
  name: Bob
  age: 10

With a list value

kcl main.k -O :person.ids=\[1,2\]

Expected Output:

person:
  name: Alice
  age: 10
  ids:
    - 1
    - 2

3. What did you see instead (Required)

With a string value

kcl main.k -O :person.name=\"Bob\" -O :person.age=10

Received Output:

Error: invalid argument ":person.name=\"Bob\"" for "-O, --overrides" flag: parse error on line 1, column 14: bare " in non-quoted-field

With a list value

kcl main.k -O :person.ids=\[1,2\]

Received Output:

Error: Invalid spec format ':person.ids=[1', expected <field_path>=filed_value>, <field_path>:filed_value>, <field_path>+=filed_value> or <field_path>-

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

$ kcl --version
kcl version v0.11.1
@legal90
Copy link
Author

legal90 commented May 9, 2025

Without leading : in the dentifier - it works for integer:

$ kcl main.k -O person.age=10
person:
  name: Alice
  age: 10

But still does not work for strings:

$ kcl main.k -O 'person.name=\"Bob\"'
Error: invalid argument "person.name=\\\"Bob\\\"" for "-O, --overrides" flag: parse error on line 1, column 14: bare " in non-quoted-field
$ kcl main.k -O person.name=\"Bob\"
Error: invalid argument "person.name=\"Bob\"" for "-O, --overrides" flag: parse error on line 1, column 13: bare " in non-quoted-field
$ kcl main.k -O person.name="Bob"
Error: 
error[E2L23]: CompileError
 --> /private/tmp/main.k:7:5
  |
7 |     name = "Alice"
  |     ^ name 'Bob' is not defined
  |

@Peefy Peefy added the bug Something isn't working label May 9, 2025
@Peefy
Copy link
Contributor

Peefy commented May 9, 2025

Seems that the , in the CLI flag causes this issue, I will try to fix it.

@Peefy
Copy link
Contributor

Peefy commented May 9, 2025

For the string value, we can use the form like person.name=\'Bob\'

@Peefy
Copy link
Contributor

Peefy commented May 9, 2025

The document is also wrong, and we can remove the leading : in the override spec.

@legal90
Copy link
Author

legal90 commented May 9, 2025

Thank you, @Peefy! I confirm that person.name=\'Bob\' works as expected:

$ kcl . -O person.name=\'Bob\'
person:
  name: Bob
  age: 10

Side question:
Is the argument -d still supposed to be used for the in-place replacement of the variable in the file, like the doc says?

Besides, when we use KCL CLI -d argument, the KCL file will be modified to the following content at the same time

I find it a bit confusing, because for all other cases (including kcl run) -d used as a toggle for a debug mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants