Skip to content

fix🐛: accept the generator flags a released front end sends as booleans - #966

Merged
wenjianzhang merged 1 commit into
masterfrom
fix/gen-flags-accept-bool
Oct 27, 2026
Merged

wenjianzhang merged 1 commit into
masterfrom
fix/gen-flags-accept-bool

Conversation

@wenjianzhang

@wenjianzhang wenjianzhang commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

问题

用户反馈代码生成配置页保存报 数据解析失败。

go-admin-ui v3.4.0 及之前的版本把 isDataScope / isActions / isAuth 作为布尔值提交,后端 SysTables 中这三个字段是 int,JSON 解析失败。前端修复(go-admin-ui f0e112e,#323)尚未进入任何发布版本,而两个仓库各自独立升级,所以后端需要兼容。

修改

新增 tools.GenFlag(1 = 是,2 = 否),三个字段改用该类型:

  • 数字、数字字符串照常解析;
  • 布尔值或 null 视为未传(0)。Updates 跳过零值,库中原有设置保持不变;
  • 其他非法值仍报错。

不把 false 映射为 2:v3.4.0 加载时把 1 转成 "1",提交时判断 "1" === 'true',三个值永远是 false。如果做映射,每次保存都会把 isAuth 改成 2,生成的路由就不再检查角色。

数据库列类型不变,gen.go 中 IsAuth == 2 的判断不受影响。

验证

  • 新增 gen_flag_test.go:覆盖各种输入的解析;验证 v3.4.0 的请求体保存后,标志位保持不变、其他字段正常写入。
  • 在 sqlite 上启动真实服务,分别重放 v3.4.0(布尔值)和当前 master 前端(整数)的保存请求,均返回 200,库中值保持 1|2|1。修复前,布尔值请求返回 数据解析失败。
  • go test ./...、make checksilent 通过。

Copilot AI balanced review requested due to automatic review settings October 27, 2026 02:17

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The focused compatibility change preserves existing settings, includes regression coverage, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR makes generator configuration saves compatible with released front ends that submit boolean flags, while preserving stored settings rather than interpreting false as disabling authorization.

Changes:

  • Adds GenFlag parsing for integers and numeric strings, treating booleans and null as unset.
  • Applies the type to the three generator flags without changing database column types.
  • Adds parsing tests and a persistence regression test confirming boolean submissions preserve flags while saving other fields.
File Description
app/​other/​models/​tools/​sys_tables.go Uses GenFlag for data-scope, Actions, and authorization settings.
app/​other/​models/​tools/​gen_flag.go Implements backward-compatible JSON flag parsing.
app/​other/​models/​tools/​gen_flag_test.go Tests parsing and preservation of stored flags during updates.

Review effort: Balanced

go-admin-ui up to v3.4.0 submits isDataScope / isActions / isAuth as
booleans, which failed to unmarshal into int and made every save of the
code generator config answer 数据解析失败. The front-end fix (go-admin-ui
f0e112e) is in no release yet, and the two repositories upgrade
independently.

Those booleans are always false whatever is stored, so they are read as
unset and the stored value is kept, rather than mapped to 2: turning
false into "no" would drop the role check from every generated router.
Numbers and numeric strings still parse as before.
@wenjianzhang
wenjianzhang force-pushed the fix/gen-flags-accept-bool branch from 8d5dfc6 to 11f4070 Compare October 27, 2026 02:25
@wenjianzhang
wenjianzhang merged commit f24c303 into master Oct 27, 2026
5 checks passed
@wenjianzhang
wenjianzhang deleted the fix/gen-flags-accept-bool branch October 27, 2026 02:33
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.

2 participants