From b24b8524b624638e8965a250238610015ba83b16 Mon Sep 17 00:00:00 2001 From: Sanaei Date: Mon, 8 Jun 2026 23:04:19 +0200 Subject: [PATCH] fix(inbounds): drop unknown nodeId when importing an inbound Importing an inbound that was exported from another panel (or whose node was later deleted) carried a non-zero nodeId referencing a node that does not exist on the importing panel. AddInbound -> nodePushPlan -> NodeSyncState looked that node up and returned gorm's "record not found", so the import failed with "Something went wrong Failed: record not found". Node IDs are panel-local and not portable, so the import handler now drops a nodeId that does not exist on this panel (new NodeService.NodeExists helper), importing it as a local inbound instead of erroring. This mirrors the existing nodeId==0 normalization in the same handler. --- web/controller/inbound.go | 12 ++++++++++-- web/service/node.go | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 10e334e3f..706b1fa09 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -350,8 +350,16 @@ func (a *InboundController) importInbound(c *gin.Context) { user := session.GetLoginUser(c) inbound.Id = 0 inbound.UserId = user.Id - if inbound.NodeID != nil && *inbound.NodeID == 0 { - inbound.NodeID = nil + // Node IDs are panel-local and not portable across panels. Drop a node + // reference that is zero or that points to a node which doesn't exist on + // this panel, so a cross-panel export imports as a local inbound instead of + // failing with "record not found" when nodePushPlan looks the node up. + if inbound.NodeID != nil { + if *inbound.NodeID == 0 { + inbound.NodeID = nil + } else if exists, err := (&service.NodeService{}).NodeExists(*inbound.NodeID); err == nil && !exists { + inbound.NodeID = nil + } } for index := range inbound.ClientStats { diff --git a/web/service/node.go b/web/service/node.go index 785e5e08e..51525f7cb 100644 --- a/web/service/node.go +++ b/web/service/node.go @@ -298,6 +298,20 @@ func (s *NodeService) GetById(id int) (*model.Node, error) { return n, nil } +// NodeExists reports whether a node with the given id exists on this panel. +// Used to drop stale, cross-panel node references on inbound import. A Count +// query distinguishes "no such node" (count 0, no error) from a real DB error. +func (s *NodeService) NodeExists(id int) (bool, error) { + if id <= 0 { + return false, nil + } + var count int64 + if err := database.GetDB().Model(model.Node{}).Where("id = ?", id).Count(&count).Error; err != nil { + return false, err + } + return count > 0, nil +} + func normalizeBasePath(p string) string { p = strings.TrimSpace(p) if p == "" {