openfga icon indicating copy to clipboard operation
openfga copied to clipboard

Incorrect implementation of `tuple.SplitObject`

Open miparnisari opened this issue 1 year ago • 4 comments

Checklist

  • [X] I have looked into the README and have not found a suitable solution or answer.
  • [X] I have looked into the documentation and have not found a suitable solution or answer.
  • [X] I have searched the issues and have not found a suitable solution or answer.
  • [X] I have upgraded to the latest version of OpenFGA and the issue still persists.
  • [X] I have searched the OpenFGA Community and have not found a suitable solution or answer.
  • [X] I agree to the terms within the OpenFGA Code of Conduct.

Description

It seems to me that tuple.SplitObject(obj) is incorrectly implemented.

  1. it supports an input such as group#member:fga, which is invalid.
  2. for a valid input group:fga#member it returns group, fga#member . It should be group, member, fga.

Luckily, when we pass a userset as input, we always discard the second return value, so this doesn't manifest in any bugs.

Expectation

  • tuple.SplitObject should accept correctly formatted usersets as inputs.
  • If it's possible, I recommend changing the return types from (typeAndRelation, id) to (type, relation, id) and deprecate SplitObjectRelation. These two functions almost always are called together, which is a code smell.

Reproduction

n/a

Store data

No response

OpenFGA version

1.5.7

How are you running OpenFGA?

As a binary

What datastore are you using?

In-Memory

OpenFGA Flags

none

Logs

No response

miparnisari avatar Jul 30 '24 06:07 miparnisari

Hey @miparnisari , I've been looking for a good issue to start contributing and I saw this one referenced in https://github.com/openfga/openfga/pull/1615#discussion_r1747483797. Do you think it's an appropriate time for me to pick this one up since it has a bunch of references throughout the code?

Jguer avatar Oct 31 '24 10:10 Jguer

Hey @Jguer! You can try to do it, but i'm honestly not sure if it will be an easy first task since like you said it's being referenced in a bunch of places. You will likely experience unit test failures. I recommend timeboxing the refactor to half an hour and then publish a PR, and we can take it from there if you wish.

miparnisari avatar Oct 31 '24 18:10 miparnisari

@miparnisari just a sidenote: group:fga#member is an invalid object, I don't think it should return group, member, fga.

Unless you want a SplitUserset

rhamzeh avatar Oct 31 '24 19:10 rhamzeh

@rhamzeh yes, if anything, SplitObject should have been called SplitUserset 😓

using tuple.ToUserParts will get rid of the ambiguity.

miparnisari avatar Oct 31 '24 19:10 miparnisari