casbin / casbin-server

Casbin as a Service (CaaS)
https://casbin.org/docs/service
Apache License 2.0
305 stars 98 forks source link

GORM adapter is unable to read "PType" column #71

Closed nsarup closed 1 year ago

nsarup commented 2 years ago

Issue:

  1. I have a database written by the casbin API (which uses the casbin-pg-adapter).

  2. The structure of the database looks like:

    Screenshot 2022-08-15 at 04 39 06
  3. The GORM adapter is able to read columns V0-5 but unable to read column ptype in the CasbinRule structure.

  4. As a result a panic is thrown

casbin-bot commented 2 years ago

@tangyang9464 @JalinWang @imp2002

hsluoyz commented 2 years ago

@nsarup see: https://github.com/casbin/gorm-adapter/issues/156#issuecomment-1087207204

JalinWang commented 2 years ago

@nsarup see: casbin/gorm-adapter#156 (comment)

I think it's probably caused by other fields. gorm-adapter now has 8 fields while `casbin-pg-adapter only has 6.

// in GORM-adapter
type CasbinRule struct {
    ID    uint   `gorm:"primaryKey;autoIncrement"`
    Ptype string `gorm:"size:100"`
    V0    string `gorm:"size:100"`
    V1    string `gorm:"size:100"`
    V2    string `gorm:"size:100"`
    V3    string `gorm:"size:100"`
    V4    string `gorm:"size:100"`
    V5    string `gorm:"size:100"`
    V6    string `gorm:"size:25"`
    V7    string `gorm:"size:25"`
}

In casbin-pg-adapter: https://github.com/casbin/casbin-pg-adapter/blob/master/adapter.go#L19-L29

hsluoyz commented 2 years ago

@JalinWang he said:

The GORM adapter is able to read columns V0-5 but unable to read column ptype in the CasbinRule structure.

So I think v6 and v7 will not cause ptype to fail?

Actually, what's your suggested solution for this issue?

JalinWang commented 2 years ago

Can we remove extra fields in gorm-adapter? Other adapters only have v0-v5. @tangyang9464

hsluoyz commented 2 years ago

@JalinWang we just added v6 and v7 in PR: https://github.com/casbin/gorm-adapter/pull/157 , you should find another solution

hsluoyz commented 1 year ago

@nsarup gorm-adapter has reverted the PR and restored to use up to v5 fields: https://github.com/casbin/gorm-adapter/pull/181 , now we need to upgrade the gorm-adapter version in this repo