fix: preserve boolean/numeric types when panel expands template varia…#177
fix: preserve boolean/numeric types when panel expands template varia…#177parkervcp merged 4 commits intopelican-dev:mainfrom
Conversation
|
Warning Rate limit exceeded
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 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. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
ParseFloatwhen the existing JSON value is numeric.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 thantrue. That meansReplaceWith.Type()is alwaysjsonparser.Stringby the time Wingssees it, so the boolean branch inside
getKeyValuewas never reachable.On top of that, egg variables typed as "boolean" in the panel only produce
0and1.To actually get
true/falsestrings you have to use anin:true,falsevalidation rule— which means the value is by definition a string, never a JSON boolean.
End result: a field that holds
truein 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
getKeyValuenow receives the value that already lives at the target path in the parseddocument. Because
gabsusesencoding/jsonunder the hood, booleans are Goboolandnumbers are
float64. A simple type switch on the existing value is enough to pick theright 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:
The panel sends
"replace_with": "true"(a string, because template expansion always produces a string)."dry_run": "true"❌ string"dry_run": true✅ booleanNotes
ReplaceWith.Type() == jsonparser.Booleanbranch is kept for completeness butremains unreachable in practice — no panel sends a bare JSON boolean as the
replacement value.
float64covers both integers and floats since that is whatencoding/jsonproducesfor all JSON numbers.
Summary by CodeRabbit