casbin / xorm-adapter

Xorm adapter for Casbin
https://github.com/casbin/casbin
Apache License 2.0
384 stars 58 forks source link

Interface conversion (Panic) *xormadapter.Adapter is not persist.UpdatableAdapter: missing method UpdatePolicies #38

Closed kevin-nessie closed 3 years ago

kevin-nessie commented 3 years ago

Description

Panic error when trying to use the function UpdateGroupingPolicy() or UpdateNamedGroupingPolicy()

The xormadapter.Adapter cannot be converted to persist.UpdatableAdapter because of missing function UpdatePolicies() in the xorm-adapter

stacktrace

panic serving [::1]:35256: interface conversion: *xormadapter.Adapter is not persist.UpdatableAdapter: missing method UpdatePolicies
goroutine 23 [running]:
net/http.(*conn).serve.func1(0xc0002981e0)
        /snap/go/current/src/net/http/server.go:1824 +0x14c
panic(0xb14e60, 0xc0003d6ba0)
        /snap/go/current/src/runtime/panic.go:971 +0x4c7
github.com/casbin/casbin/v2.(*Enforcer).updatePolicy(0xc00038a780, 0xb8e9f8, 0x1, 0xb8e9f8, 0x1, 0xc0003d6b40, 0x3, 0x3, 0xc0003d6b70, 0x3, ...)
        /home/kserrano/go/pkg/mod/github.com/casbin/casbin/v2@v2.25.5/internal_api.go:154 +0x1d5
github.com/casbin/casbin/v2.(*Enforcer).UpdateNamedGroupingPolicy(0xc00038a780, 0xb8e9f8, 0x1, 0xc0003d6b40, 0x3, 0x3, 0xc0003d6b70, 0x3, 0x3, 0xe73500, ...)
        /home/kserrano/go/pkg/mod/github.com/casbin/casbin/v2@v2.25.5/management_api.go:314 +0xd8
github.com/casbin/casbin/v2.(*Enforcer).UpdateGroupingPolicy(0xc00038a780, 0xc0003d6b40, 0x3, 0x3, 0xc0003d6b70, 0x3, 0x3, 0x0, 0x0, 0x0)
        /home/kserrano/go/pkg/mod/github.com/casbin/casbin/v2@v2.25.5/management_api.go:310 +0xbe
nessie.xyz/authorization/internal/models.UpdateMember(0xc00051c1a0, 0xc0002a4290, 0x6, 0xc0002a42b0, 0xa, 0xc0002a42c0, 0xb, 0xc0002a4296, 0x6, 0xc0002a42a0, ...)

Versions

Using the following versions for Casbin and Adapter (extracted from go.mod file) Casbin v2.25.5 (latest as of today) xorm-adapter v2.2.0 (latest as of today)

go 1.15

require (
    github.com/casbin/casbin/v2 v2.25.5
    github.com/casbin/xorm-adapter/v2 v2.2.0
    github.com/go-sql-driver/mysql v1.5.0
)
hsluoyz commented 3 years ago

@kevin-nessie a fixed version is released: https://github.com/casbin/xorm-adapter/releases/tag/v2.3.0

kevin-nessie commented 3 years ago

thank you! I just gave it a try and it works :)