Skip to content

feat(core): cast valid booleans when setting system configs - #58868

Open
skjnldsv wants to merge 1 commit into
masterfrom
feat/cast-bool-system-config
Open

feat(core): cast valid booleans when setting system configs#58868
skjnldsv wants to merge 1 commit into
masterfrom
feat/cast-bool-system-config

Conversation

@skjnldsv

Copy link
Copy Markdown
Member

I think we could be smarter with primitive values like those 🙈

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@skjnldsvskjnldsv added this to the Nextcloud 34 milestone Mar 11, 2026
@skjnldsvskjnldsv self-assigned this Mar 11, 2026
@skjnldsv
skjnldsv requested a review from a team as a code ownerMarch 11, 2026 14:47
@skjnldsvskjnldsv added 3. to review Waiting for reviews papercut Annoying recurring UX issue with possibly simple fix. labels Mar 11, 2026
@skjnldsv
skjnldsv requested review from CarlSchwan, artonge, come-nc and icewind1991 and removed request for a teamMarch 11, 2026 14:47
Comment threadcore/Command/Config/System/SetConfig.php Outdated

@come-nccome-nc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But that would mean when setting a configuration to "false" or "true" it would automagically decide that it’s a boolean even if we indicated type string?
That seems dangerous to me.
Maybe output a warning but do not change the type on the fly.

Otherwise how would one set a configuration to the string "true", it would not be possible anymore?

@skjnldsv

skjnldsv commented Mar 17, 2026

Copy link
Copy Markdown
MemberAuthor

But that would mean when setting a configuration to "false" or "true" it would automagically decide that it’s a boolean even if we indicated type string? That seems dangerous to me. Maybe output a warning but do not change the type on the fly.

Otherwise how would one set a configuration to the string "true", it would not be possible anymore?

We do not have any
https://github.com/nextcloud/server/blob/bb4c9ecc0e316782227570257856891995b1e369/config/config.sample.php

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
artonge

This comment was marked as outdated.

@artongeartonge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw that Côme had the same comment. Given your answer, I say let's go!

@come-nc

Copy link
Copy Markdown
Contributor

But that would mean when setting a configuration to "false" or "true" it would automagically decide that it’s a boolean even if we indicated type string? That seems dangerous to me. Maybe output a warning but do not change the type on the fly.
Otherwise how would one set a configuration to the string "true", it would not be possible anymore?

We do not have any https://github.com/nextcloud/server/blob/bb4c9ecc0e316782227570257856891995b1e369/config/config.sample.php

We do not have any what? String in the configuration?

If the dbuser is named "true" or it’s the smtp password or whatever, now the command will silently set it to a boolean despite being called with --type string. That’s misleading. It should at the very least output a warning when the type was explicitly set and it does an auto-conversion.
I’m fine with guessing the type when --type was not passed, but silently not respecting an explicit option is bad behavior.

@joshtrichards

Copy link
Copy Markdown
Member

Given we already cast at the explicit direction of the user prior to this if type is specified, it seems a little weird, at least under those circumstances:

$configValue = $this->castHelper->castValue($input->getOption('value'), $input->getOption('type'));
$updateOnly = $input->getOption('update-only');
// If value is string false or true, cast them too
if (is_string($configValue['value'])) {
$lowerValue = strtolower($configValue['value']);

e.g. --type string --value="true"

Also little weird if we only do this for system, not app. ;-)

I’m fine with guessing the type when --type was not passed, but silently not respecting an explicit option is bad behavior.

This ^^^.

And --type must never be overridden -- even with a warning (except for when it's impossible/unrealistic).

P.S. Also it hadn't occurred to me how distinct OC\Core\Command\Config\App and OC\Core\Command\Config\System's implementations are until just now:

$type = $typeString = null;
if ($input->hasParameterOption('--type')) {
$typeString = $input->getOption('type');
$type = $this->appConfig->convertTypeToInt($typeString);
}

if ($type !== null && $type !== $this->appConfig->getValueType($appName, $configName) && $typeString !== null && $this->ask($input, $output, $typeString)) {
$updated = $this->appConfig->updateType($appName, $configName, $type) || $updated;
}
} else {
/**
* If --type is specified in the command line, we upgrade the type in database
* after a confirmation from admin.
* If not we get the type from current stored value or VALUE_MIXED as default.
*/
try {
$currType = $this->appConfig->getValueType($appName, $configName);
if ($type === null || $typeString === null || $type === $currType || !$this->ask($input, $output, $typeString)) {
$type = $currType;
} else {
$updated = $this->appConfig->updateType($appName, $configName, $type);
}
} catch (AppConfigUnknownKeyException) {
$type = $type ?? IAppConfig::VALUE_MIXED;
}

@come-nc

Copy link
Copy Markdown
Contributor

Also config.sample.php is not complete, see #59911
twofactor_enforced is a string boolean.

@nextcloud-botnextcloud-bot mentioned this pull request May 27, 2026
@nextcloud-botnextcloud-bot mentioned this pull request Jun 4, 2026
This was referenced Jun 5, 2026
@susnuxsusnux removed this from the Nextcloud 34.0.1 milestone Jun 9, 2026
@susnuxsusnux added this to the Nextcloud 35 milestone Jun 9, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to reviewWaiting for reviewspapercutAnnoying recurring UX issue with possibly simple fix.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@skjnldsv@come-nc@joshtrichards@artonge@CarlSchwan@susnux@nextcloud-bot