Skip to content

Upgrade to Casbin v3#70

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-xorm-adapter-support
Open

Upgrade to Casbin v3#70
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-xorm-adapter-support

Conversation

Copy link

Copilot AI commented Jan 27, 2026

The adapter was using Casbin v2 dependencies, causing interface type mismatches when used with Casbin v3 enforcers:

panic: interface conversion: *xormadapter.Adapter is not persist.Adapter: missing method LoadPolicy

Changes

  • Dependencies: github.com/casbin/casbin/v2v3
  • API compatibility: Handle GetPolicy() now returning ([][]string, error) in tests
  • Documentation: Update README examples to show v3 imports

The adapter implementation required no changes - all persist.Adapter methods were already present. The issue was purely an import path mismatch between v2 and v3 type systems.

Usage

import (
    "github.com/casbin/casbin/v3"
    xormadapter "github.com/casbin/xorm-adapter/v3"
)

adapter, _ := xormadapter.NewAdapterByEngineWithTableName(engine, "policy", "t_")
enforcer, _ := casbin.NewSyncedCachedEnforcer(modelFile, adapter)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • go.googlesource.com
    • Triggering command: /update-job-proxy /update-job-proxy ut-80144385.c -fmessage-length--source-root ache/go/1.24.12//home/REDACTED/work/xorm-adapter/xorm-adapter -E 1997253/b181/_pkg_.a ctor ache/go/1.24.12/x64/pkg/tool/linux_amd64/vet ache/go/1.24.12/git r/goleveldb/leverev-parse -fno-stack-proteFETCH_HEAD ache/go/1.24.12/x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy DROP /usr/bin/dirnameextensions.objectformat test -e stitutions_ECC_RootCA_2015.pem dirname /opt/go/bin/test (dns block)
  • xorm.io
    • Triggering command: /update-job-proxy /update-job-proxy ut-80144385.c -fmessage-length--source-root ache/go/1.24.12//home/REDACTED/work/xorm-adapter/xorm-adapter -E 1997253/b181/_pkg_.a ctor ache/go/1.24.12/x64/pkg/tool/linux_amd64/vet ache/go/1.24.12/git r/goleveldb/leverev-parse -fno-stack-proteFETCH_HEAD ache/go/1.24.12/x64/pkg/tool/linux_amd64/vet (dns block)
    • Triggering command: /update-job-proxy /update-job-proxy DROP /usr/bin/dirnameextensions.objectformat test -e stitutions_ECC_RootCA_2015.pem dirname /opt/go/bin/test (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Are there any plans for xorm-adapter to support Casbin v3?</issue_title>
<issue_description>To use the xorm-adapter in Casbin v3, do the following:

	adapter, err := xormadapter.NewAdapterByEngineWithTableName(database.OrmDb, "ram_policy", "t_")
	if err != nil {
		return enforcer, err
	}
	super, err := s.getSuperAdminRoleId()
	if err != nil {
		return enforcer, err
	}
	modelfile, err := s.defaultModel(super, defaultDataTagWhenInter)
	if err != nil {
		return enforcer, err
	}
	enforcer, err = casbin.NewSyncedCachedEnforcer(modelfile, adapter)

The following error was returned:

panic: interface conversion: *xormadapter.Adapter is not persist.Adapter: missing method LoadPolicy
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits January 27, 2026 09:18
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix xorm-adapter to support Casbin v3 Upgrade to Casbin v3 Jan 27, 2026
Copilot AI requested a review from hsluoyz January 27, 2026 09:24
@hsluoyz hsluoyz marked this pull request as ready for review January 27, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Are there any plans for xorm-adapter to support Casbin v3?

3 participants