Skip to content

fix: preserve boolean/numeric types when panel expands template varia…#177

Merged
parkervcp merged 4 commits intopelican-dev:mainfrom
gOOvER:boolean
May 7, 2026
Merged

fix: preserve boolean/numeric types when panel expands template varia…#177
parkervcp merged 4 commits intopelican-dev:mainfrom
gOOvER:boolean

Conversation

@gOOvER
Copy link
Copy Markdown
Contributor

@gOOvER gOOvER commented May 5, 2026

fix: preserve boolean and numeric types when config values come from template variables

What's happening

When the panel builds the replacement instructions for a config file, variables like
{{server.environment.DRY_RUN}} get sent as plain JSON strings — "true" rather than
true. That means ReplaceWith.Type() is always jsonparser.String by the time Wings
sees it, so the boolean branch inside getKeyValue was never reachable.

On top of that, egg variables typed as "boolean" in the panel only produce 0 and 1.
To actually get true/false strings you have to use an in:true,false validation rule
— which means the value is by definition a string, never a JSON boolean.

End result: a field that holds true in the config file gets overwritten with the string
"true". For software that validates its config against a schema on startup (Freqtrade,
for example) that causes an immediate crash.

The fix

getKeyValue now receives the value that already lives at the target path in the parsed
document. Because gabs uses encoding/json under the hood, booleans are Go bool and
numbers are float64. A simple type switch on the existing value is enough to pick the
right conversion before writing back — no guessing from the incoming string alone.

Fields that have no existing value (newly added keys) fall through to the old behaviour,
so nothing breaks for the common case.

Before / after

The game's config file contains:

"dry_run": true

The panel sends "replace_with": "true" (a string, because template expansion always produces a string).

Result in config file
Before "dry_run": "true" ❌ string
After "dry_run": true ✅ boolean

Notes

  • The ReplaceWith.Type() == jsonparser.Boolean branch is kept for completeness but
    remains unreachable in practice — no panel sends a bare JSON boolean as the
    replacement value.
  • float64 covers both integers and floats since that is what encoding/json produces
    for all JSON numbers.

Summary by CodeRabbit

  • Bug Fixes
    • Improved type preservation in configuration value handling during template expansion. Boolean values and numeric values now correctly maintain their original data types when updating existing configuration properties, ensuring consistency across configuration updates.

@gOOvER gOOvER requested a review from a team as a code owner May 5, 2026 11:25
Copilot AI review requested due to automatic review settings May 5, 2026 11:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 5, 2026

Warning

Rate limit exceeded

@gOOvER has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 4 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e72ba31f-f7e8-45e0-a716-a793a8837b64

📥 Commits

Reviewing files that changed from the base of the PR and between 0586630 and e9a0827.

📒 Files selected for processing (1)
  • parser/helpers.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes JSON config replacements so that values originating from template variables (which arrive as strings) can preserve the existing JSON value type (notably booleans and numbers) when updating an already-present key in a config document.

Changes:

  • Improves boolean parsing to avoid silently converting invalid booleans, with a warning-based fallback.
  • Updates JSON replacement logic to mirror the type already present at the target JSON path (boolean/number) before writing via sjson.
  • Adds number handling via ParseFloat when the existing JSON value is numeric.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread parser/helpers.go
Comment thread parser/helpers.go
Comment thread parser/helpers.go Outdated
Copy link
Copy Markdown
Member

@parkervcp parkervcp left a comment

Choose a reason for hiding this comment

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

LGTM

@parkervcp parkervcp merged commit a57491d into pelican-dev:main May 7, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

3 participants