Hi! New to the community here.
# spicedb
s
Hi! New to the community here. I was wondering if there are any issues with having a cyclical relationship We have a use case where we are trying to allowlist the members of certain channels for certain SKUs. In our application, we will do some LookupResource request to get the SKUs that a person can see. Our schema looks something like
Copy code
definition example/channel {
    relation admin_members: example/admins
    relation user_members: example/users

}


definition example/admins {
    relation channel: example/channel
}

definition example/users {
    relation channel: example/channel

}


definition example/skus {
    relation allowlisted_channel_members: example/channel#admin_members | example/channel#user_members

    permission view_sku = allowlisted_channel_members

}
Is there any issue with having a cyclical relationship like user->channel and channel->user? Is there maybe another way to structure this to avoid having the channel->user & channel->admin relations?
y
a cyclical definition isn't a problem unless you end up with cyclical data. sometimes this sort of cyclical structure makes sense for the logic you want to express.
that said, if you can avoid it i'd recommend it, because you'll get precondition failures and then have to go debug the data cycle and that'll be a pain
unless you can otherwise enforce invariants in your system that will prevent that from being an issue
but there's nothing in SpiceDB that prevents you from doing so
s
Thank You for the response! > because you'll get precondition failures and then have to go debug the data cycle and that'll be a pain Can You explain that a bit more please?
y
SpiceDB has a max recursion depth limit. if you hit that limit, such as because you have a cycle in your data, you'll receive a
PRECONDITION_FAILED
gRPC error.
if you hit that limit for a check, the only way to fix it will be to go and identify the cycle in your data and break it somehow, or else avoid making that particular request that triggered the condition.
5 Views