From ca7619af41d96c5cc7ba63111b076a7fd3cada79 Mon Sep 17 00:00:00 2001 From: Yavolte Date: Wed, 30 Jul 2025 13:57:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8E=B7=E5=8F=96RuntimeScop?= =?UTF-8?q?e=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model.go | 6 +++++- rest.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/model.go b/model.go index af5b5c4..c1f9965 100644 --- a/model.go +++ b/model.go @@ -1025,7 +1025,11 @@ func (m *Model) Import(w http.ResponseWriter, r *http.Request) { return } //这里用background的context - childCtx := context.WithValue(context.Background(), RuntimeScopeKey, &types.RuntimeScope{ + pCtx := m.db.Statement.Context + if pCtx == nil { + pCtx = context.Background() + } + childCtx := context.WithValue(pCtx, RuntimeScopeKey, &types.RuntimeScope{ Domain: domainName, User: m.valueLookup(types.FieldUser, w, r), ModuleName: m.naming.ModuleName, diff --git a/rest.go b/rest.go index 13924d2..3e2ae61 100644 --- a/rest.go +++ b/rest.go @@ -844,3 +844,13 @@ func OnAfterExport(cb AfterExport) { func OnAfterImport(cb AfterImport) { hookMgr.AfterImport(cb) } + +// RuntimeScopeFromContext 从上下文中获取运行时作用域 +func RuntimeScopeFromContext(ctx context.Context) *types.RuntimeScope { + if v := ctx.Value(RuntimeScopeKey); v != nil { + if scope, ok := v.(*types.RuntimeScope); ok { + return scope + } + } + return nil +}