Skip to content

ERROR CODE ATTRIBUTE TYPE MISMATCH #2117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Trandx opened this issue Mar 13, 2025 · 8 comments
Open

ERROR CODE ATTRIBUTE TYPE MISMATCH #2117

Trandx opened this issue Mar 13, 2025 · 8 comments
Assignees

Comments

@Trandx
Copy link

Trandx commented Mar 13, 2025

Hello!!
I Need help please.
I want to write data on this route permifyClient.data.write with sdk Permify-node by i've this error:
ERROR [Event] /base.v1.Data/Write NOT_FOUND: ERROR_CODE_ATTRIBUTE_TYPE_MISMATCH
ClientError: /base.v1.Data/Write NOT_FOUND: ERROR_CODE_ATTRIBUTE_TYPE_MISMATCH

this my schema

entity accounts {
    attribute accountStatus string
    permission active = hasValidAccountStatus(accountStatus)
 }
 entity tenants {
    relation parent @accounts
    relation owner @accounts
    relation admin @accounts @tenants#member
    relation member @accounts

    attribute tenantStatus string

    permission manage = parent.active and hasValidTenantStatus(tenantStatus)  and (admin or owner)
 }
 entity organizations {
    relation parent @tenants
    relation admin  @accounts
    relation member @accounts @organizations#admin
    relation banned @accounts

    permission read = member not banned
    permission create = admin not banned
    permission update = admin not banned
    permission delete = admin not banned
}

 rule hasValidAccountStatus (accountStatus string) {
	context.account.status == accountStatus
 }

 rule hasValidTenantStatus (tenantStatus string) {
    context.tenant.status == tenantStatus
 }

this my data (note date certain fields is variables values)

{
       tenantId: tenant.id,
       metadata: {
           schemaVersion
       },
       tuples: [
         {
           entity: {
             type: "tenants",
             id: tenant.id
           },
           relation: "owner",
           subject: {
             type: "accounts",
             id: account.id,
             relation:""
           }
         }
       ],
       attributes: [
         {
           entity: {
             type: "tenants",
             id: tenant.id
           },
           attribute: "tenantStatus",
           value: {
             "@type": "type.googleapis.com/base.v1.StringValue",
             data: "activated"
           }
         },
         {
           entity: {
             type: "accounts",
             id: account.id
           },
           attribute: "accountStatus",
           value: {
             "@type": "type.googleapis.com/base.v1.StringValue",
             data: "activated"
           }
         }
       ]
     }
@tolgaOzen
Copy link
Member

Hi @Trandx ,
Could you try creating the attribute like this:

import {Any} from "permify-node/grpc/generated/google/protobuf/any";

// Create a StringValue message
const stringValue = permify.grpc.base.StringValue.fromJSON({ data: "activated" });

// Create an Any message that wraps the StringValue
const message = Any.fromJSON({
    typeUrl: 'type.googleapis.com/base.v1.StringValue',
    value: permify.grpc.base.StringValue.encode(stringValue).finish()
});

Then use it like this when writing the data:

client.data.write({
    tenantId: "t1",
    metadata: {
        schemaVersion: schemaVersion
    },
    attributes: [
        {
            entity: {
                type: "tenants",
                id: "1"
            },
            attribute: "tenantStatus",
            value: message
        }
    ],
    // ...
});

Let me know if this works for you!

@Trandx
Copy link
Author

Trandx commented Mar 13, 2025

Thank you very much, it work well but, when i try to check permission, now i have this error: "/base.v1.Permission/Check INTERNAL: failed to evaluate expression: no such key: tenant"

this is my data

{
    "tenantId": "sch_54f8bbfa",
    "metadata": {
        "schemaVersion": "cv9clvhk46ec73eo3uv0",
        "snapToken": "",
        "depth": 20
    },
    "entity": {
        "type": "tenants",
        "id": "sch_54f8bbfa"
    },
    "permission": "manage",
    "subject": {
        "type": "accounts",
        "id": "7382a18d-b652-41eb-ad0b-d06d8cd657cf",
        "relation": ""
    },
    "context": {
        "account": {
            "status": "actived"
        },
        "tenant": {
            "status": "actived"
        }
    }
}

@tolgaOzen
Copy link
Member

@Trandx , Could you try with this:

{
    "tenantId": "sch_54f8bbfa",
    "metadata": {
        "schemaVersion": "cv9clvhk46ec73eo3uv0",
        "snapToken": "",
        "depth": 20
    },
    "entity": {
        "type": "tenants",
        "id": "sch_54f8bbfa"
    },
    "permission": "manage",
    "subject": {
        "type": "accounts",
        "id": "7382a18d-b652-41eb-ad0b-d06d8cd657cf",
        "relation": ""
    },
    "context": {
       "data":  
           "account": {
                "status": "actived"
            },
            "tenant": {
             "status": "actived"
        }
    }
}

then you need to change context call of your model like this:

 rule hasValidAccountStatus (accountStatus string) {
	context.data.account.status == accountStatus
 }

 rule hasValidTenantStatus (tenantStatus string) {
    context.data.tenant.status == tenantStatus
 }

@Trandx
Copy link
Author

Trandx commented Mar 13, 2025

i have the same error

I've updated the context to:

 "context": {
       "data":  {
           "account": {
                "status": "activated"
            },
            "tenant": {
               "status": "activated"
            }
        }
    }

@tolgaOzen
Copy link
Member

Hi @Trandx ,
Did you update your model like this?

entity accounts {
    attribute accountStatus string
    permission active = hasValidAccountStatus(accountStatus)
}

entity tenants {
    relation parent @accounts
    relation owner @accounts
    relation admin @accounts @tenants#member
    relation member @accounts

    attribute tenantStatus string

    permission manage = parent.active and hasValidTenantStatus(tenantStatus) and (admin or owner)
}

entity organizations {
    relation parent @tenants
    relation admin @accounts
    relation member @accounts @organizations#admin
    relation banned @accounts

    permission read = member not banned
    permission create = admin not banned
    permission update = admin not banned
    permission delete = admin not banned
}

rule hasValidAccountStatus(accountStatus string) {
    context.data.account.status == accountStatus
}

rule hasValidTenantStatus(tenantStatus string) {
    context.data.tenant.status == tenantStatus
}

After making these changes to the model, I no longer get an error when I send the following request:

{
  "metadata": {
    "schemaVersion": "",
    "snapToken": "",
    "depth": 20
  },
  "entity": {
    "type": "tenants",
    "id": "sch_54f8bbfa"
  },
  "permission": "manage",
  "subject": {
    "type": "accounts",
    "id": "7382a18d-b652-41eb-ad0b-d06d8cd657cf",
    "relation": ""
  },
  "context": {
    "data": {
      "account": {
        "status": "actived"
      },
      "tenant": {
        "status": "actived"
      }
    }
  }
}

Can you double-check to confirm everything looks good?

@Trandx
Copy link
Author

Trandx commented Mar 15, 2025

okay, let's me check!

@Trandx
Copy link
Author

Trandx commented Mar 15, 2025

After many verification and checks i have each time this response.

{
    "can": 2, // not_allwed
    "metadata": {
        "checkCount": 1
    }
}

I've verified my data relation and my data checking

@tolgaOzen
Copy link
Member

Hi @Trandx , could you send me all the relationships and attributes you created?

@tolgaOzen tolgaOzen self-assigned this Mar 17, 2025
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

No branches or pull requests

2 participants