From c010710b321fa9740d97d8cf6e55594a79459121 Mon Sep 17 00:00:00 2001 From: Rogee Date: Thu, 25 Dec 2025 11:20:56 +0800 Subject: [PATCH] fix: tenant apply gorm panic --- backend/app/http/web/tenant_apply.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/app/http/web/tenant_apply.go b/backend/app/http/web/tenant_apply.go index ad6cb63..11b0380 100644 --- a/backend/app/http/web/tenant_apply.go +++ b/backend/app/http/web/tenant_apply.go @@ -109,9 +109,10 @@ func (ctl *tenantApply) apply(ctx fiber.Ctx, form *dto.TenantApplyForm) (*dto.Te Config: types.JSON([]byte(`{}`)), } - db := models.Q.Tenant.WithContext(ctx).UnderlyingDB() + // NOTE: 使用全新 Session,避免复用 gen.DO 内部带 Model/Statement 的 *gorm.DB 导致 schema 与 dest 不一致而触发 GORM 反射 panic。 + db := models.Q.Tenant.WithContext(ctx).UnderlyingDB().Session(&gorm.Session{}) err = db.Transaction(func(tx *gorm.DB) error { - if err := tx.Create(tenant).Error; err != nil { + if err := tx.Omit("Users").Create(tenant).Error; err != nil { return err }