Hello <@U08614ZV82F> I am creating a ReBAC setup a...
# permit-saas
t
Hello @Ask Inkeep I am creating a ReBAC setup and creating resource relations using the Python SDK and when it tries to run the code below, i get this error:
ERROR:scripts.setup_rebac:Error setting up ReBAC structure: 'PermitApiClient' object has no attribute 'resource_relations
Copy code
await permit_client.api.resource_relations.create(
            "document",
            {"key": "parent", "name": "Parent", "subject_resource": "department"},
        )
a
Thanks for tagging me @Taofiq Aiyelabegan. I'll look through relevant sources and get back to you shortly.
The Python SDK uses
resource_relations
as a property on the API client. Based on the Python SDK source, the correct usage is:
Copy code
await permit.api.resource_relations.create(
    "document",
    {
        "key": "parent",
        "name": "Parent",
        "subject_resource": "department",
    }
)
(1) Make sure you're using
permit.api.resource_relations
(not
permit_client.api.resource_relations
) , and that your
permit
object is properly initialized with the Permit SDK. If you're still encountering this error, please share the following so our engineers can investigate: 1. Which Workspace / Project / Environment you're using 2. The full SDK initialization code you're using 3. Which PDP version you're running 4. Any relevant logs from your PDP Also, ensure you have the latest version of the Python SDK installed:
Copy code
pip install permit
(1)
t
Copy code
from permit import Permit   
permit_client = Permit(token=PERMIT_API_KEY, pdp=PERMIT_PDP_URL)
I am initializing the client here
Copy code
from permit import Permit   
permit_client = Permit(token=PERMIT_API_KEY, pdp=PERMIT_PDP_URL)
I am initializing the client here
@Ask Inkeep
a
Thanks for tagging me @Taofiq Aiyelabegan. I'll look through relevant sources and get back to you shortly.
* Your initialization looks correct. The
resource_relations
API is available in the Python SDK, but the error suggests you may be running an older version of the SDK that doesn't include this feature. Try upgrading to the latest version:
Copy code
pip install --upgrade permit
After upgrading, your code should work:
Copy code
from permit import Permit

permit_client = Permit(token=PERMIT_API_KEY, pdp=PERMIT_PDP_URL)

await permit_client.api.resource_relations.create(
    "document",
    {"key": "parent", "name": "Parent", "subject_resource": "department"},
)
You can verify your installed version with:
Copy code
pip show permit
If upgrading doesn't resolve the issue, please share: 1. Which Workspace / Project / Environment you're using 2. The exact SDK version you have installed (
pip show permit
) 3. Which PDP version you're running 4. Any relevant logs from your PDP This will help our engineers investigate further.
Feel free to tag me with additional questions. I also appreciate feedback, it helps me improve. 👍 button 👎 button
a
Hey @Taofiq Aiyelabegan, please let us know if upgrading doesn't resolve the issue.
t
Hello @Alon Boshi this was working previously (like days ago), just started getting this error today, was any update made?
a
Thanks for clarifying! Will check with the team and will circle back to you
t
thank you
a
@Taofiq Aiyelabegan resource_relations is only in the Permit Python SDK ≥2.1.0. Please run
pip show permit
(or
pip list
) to confirm the current version.
t
used
permit==2.8.3
as i saw on PyPi and the method is getting called now
Thank you @Alon Boshi
💜 1
I'll let you know if there's any further issue
💜 1
a
🙂