mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5934] [Bug]: Failed to edit clients after upgrading from 2.9.4 due to tgId stored as empty string #4115
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4115
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @MaNixBlacks on GitHub (Jul 13, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5934
Describe the bug
After upgrading from 3x-ui 2.9.4 to 3.5.0, I can no longer edit clients that were created on the old version.
In 2.9.4, clients could be created with
tgId = ""(empty string). This value was stored in the database without any issues.After upgrading to 3.5.0, editing any of these clients fails with the following error:
Something went wrong (json: cannot unmarshal string into Go struct field Client.tgId of type int64)
The problem occurs regardless of what value I send when updating the client. Even if the request contains
tgId = 0, the update still fails because the existing database record containstgId = "".This appears to be a migration/backward compatibility issue, where old database records created by previous versions are no longer accepted by the newer version.
How to reproduce the problem
tgId = ""(empty string).Something went wrong (json: cannot unmarshal string into Go struct field Client.tgId of type int64)
Expected behavior
Clients created by previous versions should remain editable after upgrading. During migration, empty string values for tgId should either be converted to 0/null or handled for backward compatibility.
Actual behavior
Editing the client fails with:
Something went wrong (json: cannot unmarshal string into Go struct field Client.tgId of type int64)
The update cannot be completed because the existing database record contains tgId = "".
Relevant logs
Screenshots
3x-ui version
3.5.0
Xray-core version
v26.6.27
How did you install 3x-ui?
install.sh script
Operating system
Ubuntu 24.04
Which parts of the panel are affected?
Other, Backend (API endpoints, login, settings)
Browser (only if it is a UI bug)
Clients / User management
Is the panel behind a reverse proxy or CDN?
Yes — other
Before submitting
@github-actions[bot] commented on GitHub (Jul 13, 2026):
Title: Strict
int64unmarshal of legacytgIdbreaks client edit (and ~30 other code paths) for any inbound the startup migration didn't healSeverity: High
Category: Correctness
Why this matters:
Confirmed in the source.
settings.clients[]insideinbounds.settingsis parsed with a strict, typed unmarshal:model.Client.TgIDisint64(internal/database/model/model.go:817), with no customUnmarshalJSONto tolerate legacy shapes. If any client object stored in that inbound'ssettings.clients[]has a non-numerictgId(e.g. the""that 2.9.4 wrote), the whole array fails to unmarshal with exactly the error you saw, and the entire inbound's client list becomes unreadable — not just the one offending client.This is why the failure is independent of what you submit in the edit form: the request body itself unmarshals fine, but
ClientService.Updatereloads the existing inbound to locate/replace the client being edited viaoldClients, err := inboundSvc.GetClients(oldInbound)(internal/web/service/client_inbound_apply.go:546), which re-parses the same brokensettings.clients[]and fails before your submitted values are ever applied.GetClients/ParseInboundSettingsClientsis called from roughly 30 sites acrossinternal/web/service(client edit, bulk operations, traffic accounting, node sync, the Telegram bot), so one un-migrated inbound can break more than just editing.3x-ui already ships a one-shot migration meant to prevent exactly this:
normalizeInboundClientTgId()(internal/database/db.go:1352), registered as theInboundClientTgIdFixseeder (internal/database/db.go:1129) and run once automatically the first time the panel starts against a pre-existing database. It walks every inbound and rewrites any non-integertgIdinsettings.clients[]to0. This is present in the 3.5.0 source you're running, so it should have healed this on your first restart after upgrading — the fact that it apparently didn't is itself worth pinning down. One concrete gap: ifjson.Unmarshalof a given inbound's rawsettingsfails for any reason, the seeder logsInboundClientTgIdFix: skip inbound %d (invalid settings json)(internal/database/db.go:1365) and moves on, but still marks the fix as globally complete — so that inbound is never retried on a later start.Recommendation: (fix approach only, no PR — a maintainer would need to implement this)
ClientsTable's seeder already normalizes raw fields before typed-unmarshaling intoClientRecord: coerce a non-numerictgId(string/bool/null/non-integer) to0insideParseInboundSettingsClientsinstead of hard-failing, so a residual un-migrated row degrades gracefully instead of taking down every caller ofGetClients.normalizeInboundClientTgIdself-healing on retry (or at least surface skipped inbounds in a way an admin can act on), since today a single bad row permanently escapes the one-shot migration onceInboundClientTgIdFixis recorded inhistory_of_seeders.To confirm which scenario applies here (migration silently skipped this inbound vs. never ran at all), could you provide:
sqlite3 /etc/x-ui/x-ui.db "SELECT seeder_name FROM history_of_seeders WHERE seeder_name='InboundClientTgIdFix';"(adjust the path ifXUI_DB_FOLDERis customized).journalctl -u x-ui --no-pager | grep -i InboundClientTgIdFix(or the equivalent file under/var/log/x-ui, or yourXUI_LOG_FOLDERif set)."tgId": ""is still literally present:sqlite3 /etc/x-ui/x-ui.db "SELECT id, protocol, settings FROM inbounds;"— please redact UUIDs, passwords, and emails before pasting.@MHSanaei for awareness — the parsing gap and the migration's single-attempt-then-mark-done behavior both look worth addressing regardless of what the diagnostics above show.
This reply was generated automatically. A maintainer may follow up.
@MaNixBlacks commented on GitHub (Jul 13, 2026):
fast fix:
sudo -u postgres psql -d xui
UPDATE inbounds
SET settings = REPLACE(settings, '"tgId": ""', '"tgId": 0')
WHERE settings LIKE '%"tgId": ""%';
@MHSanaei commented on GitHub (Jul 23, 2026):
Fixed on main in
16b2bcf9(seeder InboundClientTgIdFix2): it normalizes a legacy stringtgIdin inbound client settings on upgrade — empty/non-numeric becomes 0, numeric strings are preserved — so clients saved by 2.9.4 no longer fail to unmarshal after upgrading. Please pull the latest; reopen if it persists.