[GH-ISSUE #5934] [Bug]: Failed to edit clients after upgrading from 2.9.4 due to tgId stored as empty string #4115

Closed
opened 2026-10-31 20:37:17 +07:00 by bsakaguchi · 3 comments
Owner

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 contains tgId = "".

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

  1. Install 3x-ui 2.9.4.
  2. Create a client with tgId = "" (empty string).
  3. Upgrade the panel to 3.5.0 without modifying the database.
  4. Open the existing client and try to edit any field.
  5. Click Save.
  6. Observe the error:

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

UI error:

Something went wrong (json: cannot unmarshal string into Go struct field Client.tgId of type int64)

Screenshots

Image Image

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

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
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 contains `tgId = ""`. 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 1. Install 3x-ui 2.9.4. 2. Create a client with `tgId = ""` (empty string). 3. Upgrade the panel to 3.5.0 without modifying the database. 4. Open the existing client and try to edit any field. 5. Click **Save**. 6. Observe the error: 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 ```shell UI error: Something went wrong (json: cannot unmarshal string into Go struct field Client.tgId of type int64) ``` ### Screenshots <img width="699" height="315" alt="Image" src="https://github.com/user-attachments/assets/8d2dab36-515f-47cc-9467-d1834f680dfe" /> <img width="793" height="103" alt="Image" src="https://github.com/user-attachments/assets/28a1ad1a-081e-4114-85d4-e26df35d54d5" /> ### 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 - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:37:17 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jul 13, 2026):

Title: Strict int64 unmarshal of legacy tgId breaks client edit (and ~30 other code paths) for any inbound the startup migration didn't heal

Severity: High

Category: Correctness

Why this matters:

Confirmed in the source. settings.clients[] inside inbounds.settings is parsed with a strict, typed unmarshal:

// internal/web/service/inbound_settings_clients.go:28
var clients []model.Client
if err := json.Unmarshal(payload.Clients, &clients); err != nil {
    return nil, err
}

model.Client.TgID is int64 (internal/database/model/model.go:817), with no custom UnmarshalJSON to tolerate legacy shapes. If any client object stored in that inbound's settings.clients[] has a non-numeric tgId (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.Update reloads the existing inbound to locate/replace the client being edited via oldClients, err := inboundSvc.GetClients(oldInbound) (internal/web/service/client_inbound_apply.go:546), which re-parses the same broken settings.clients[] and fails before your submitted values are ever applied. GetClients/ParseInboundSettingsClients is called from roughly 30 sites across internal/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 the InboundClientTgIdFix seeder (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-integer tgId in settings.clients[] to 0. 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: if json.Unmarshal of a given inbound's raw settings fails for any reason, the seeder logs InboundClientTgIdFix: 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)

  • Make the runtime parser tolerant at the point of use, the same way ClientsTable's seeder already normalizes raw fields before typed-unmarshaling into ClientRecord: coerce a non-numeric tgId (string/bool/null/non-integer) to 0 inside ParseInboundSettingsClients instead of hard-failing, so a residual un-migrated row degrades gracefully instead of taking down every caller of GetClients.
  • Separately, make normalizeInboundClientTgId self-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 once InboundClientTgIdFix is recorded in history_of_seeders.

To confirm which scenario applies here (migration silently skipped this inbound vs. never ran at all), could you provide:

  1. Whether the migration ran: sqlite3 /etc/x-ui/x-ui.db "SELECT seeder_name FROM history_of_seeders WHERE seeder_name='InboundClientTgIdFix';" (adjust the path if XUI_DB_FOLDER is customized).
  2. Panel logs from the first startup after the upgrade, filtered for the seeder: journalctl -u x-ui --no-pager | grep -i InboundClientTgIdFix (or the equivalent file under /var/log/x-ui, or your XUI_LOG_FOLDER if set).
  3. The raw settings for the affected inbound, to see whether "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.

<!-- gh-comment-id:4956453728 --> @github-actions[bot] commented on GitHub (Jul 13, 2026): **Title:** Strict `int64` unmarshal of legacy `tgId` breaks client edit (and ~30 other code paths) for any inbound the startup migration didn't heal **Severity:** High **Category:** Correctness **Why this matters:** Confirmed in the source. `settings.clients[]` inside `inbounds.settings` is parsed with a strict, typed unmarshal: ```go // internal/web/service/inbound_settings_clients.go:28 var clients []model.Client if err := json.Unmarshal(payload.Clients, &clients); err != nil { return nil, err } ``` `model.Client.TgID` is `int64` (`internal/database/model/model.go:817`), with no custom `UnmarshalJSON` to tolerate legacy shapes. If **any** client object stored in that inbound's `settings.clients[]` has a non-numeric `tgId` (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.Update` reloads the *existing* inbound to locate/replace the client being edited via `oldClients, err := inboundSvc.GetClients(oldInbound)` (`internal/web/service/client_inbound_apply.go:546`), which re-parses the same broken `settings.clients[]` and fails before your submitted values are ever applied. `GetClients`/`ParseInboundSettingsClients` is called from roughly 30 sites across `internal/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 the `InboundClientTgIdFix` seeder (`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-integer `tgId` in `settings.clients[]` to `0`. 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: if `json.Unmarshal` of a given inbound's raw `settings` fails for *any* reason, the seeder logs `InboundClientTgIdFix: 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) - Make the runtime parser tolerant at the point of use, the same way `ClientsTable`'s seeder already normalizes raw fields before typed-unmarshaling into `ClientRecord`: coerce a non-numeric `tgId` (string/bool/null/non-integer) to `0` inside `ParseInboundSettingsClients` instead of hard-failing, so a residual un-migrated row degrades gracefully instead of taking down every caller of `GetClients`. - Separately, make `normalizeInboundClientTgId` self-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 once `InboundClientTgIdFix` is recorded in `history_of_seeders`. To confirm which scenario applies here (migration silently skipped this inbound vs. never ran at all), could you provide: 1. Whether the migration ran: `sqlite3 /etc/x-ui/x-ui.db "SELECT seeder_name FROM history_of_seeders WHERE seeder_name='InboundClientTgIdFix';"` (adjust the path if `XUI_DB_FOLDER` is customized). 2. Panel logs from the first startup after the upgrade, filtered for the seeder: `journalctl -u x-ui --no-pager | grep -i InboundClientTgIdFix` (or the equivalent file under `/var/log/x-ui`, or your `XUI_LOG_FOLDER` if set). 3. The raw settings for the affected inbound, to see whether `"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.*
Author
Owner

@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": ""%';

<!-- gh-comment-id:4961910217 --> @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": ""%';
Author
Owner

@MHSanaei commented on GitHub (Jul 23, 2026):

Fixed on main in 16b2bcf9 (seeder InboundClientTgIdFix2): it normalizes a legacy string tgId in 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.

<!-- gh-comment-id:5059100009 --> @MHSanaei commented on GitHub (Jul 23, 2026): Fixed on main in 16b2bcf9 (seeder InboundClientTgIdFix2): it normalizes a legacy string `tgId` in 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.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#4115
No description provided.