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

Incorrect type-cast for boolean config values #22343

Closed
the-other-dev opened this issue Apr 30, 2024 · 2 comments
Closed

Incorrect type-cast for boolean config values #22343

the-other-dev opened this issue Apr 30, 2024 · 2 comments
Labels

Comments

@the-other-dev
Copy link
Contributor

the-other-dev commented Apr 30, 2024

Describe the Bug

For config options there is an automatic type-casting (https://docs.directus.io/self-hosted/config-options.html#type-casting-and-nesting). In the code, the relevant parts are in the env package lib/cast.ts and utils/guess-type.ts.

When using an actual boolean value in the config options, the parsed value turns into 0 instead of false or 1 instead of true.

I believe that this issue is there since version v10.9.0 when the env package was introduced.

To Reproduce

Add an option with the type boolean to the config.json, e.g. "MY_VARIABLE": false.
Retrieve the parsed value via:

const env = useEnv();
console.log(env['MY_VARIABLE']); // Prints 0 instead of false

The current work-around is to define the option as a string "MY_VARIABLE": "false" (returns false in the application).

Also, here are two test cases for guess-type.test.ts that currently fail due to the issue:

test('Returns boolean if value is boolean true', () => {
    expect(guessType(true)).toBe('boolean'); // Fails because it returns "number" currently
});

test('Returns boolean if value is boolean false', () => {
    expect(guessType(false)).toBe('boolean'); // Fails because it returns "number" currently
});

Directus Version

v10.10.7

Hosting Strategy

Self-Hosted (Docker Image)

@hanneskuettner
Copy link
Contributor

hanneskuettner commented Apr 30, 2024

Heya! Thank you for opening this issue, as it turns out, this looks like a duplicate of #21744. I'll proceed to close this issue. You can follow along in #21744 for the progress.

@hanneskuettner hanneskuettner closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@hanneskuettner hanneskuettner removed their assignment Apr 30, 2024
@the-other-dev
Copy link
Contributor Author

Thanks! My bad, I did not see that one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

No branches or pull requests

2 participants