Running a Python UDF fails with permission error

Ask function owner to grant EXECUTE permission.

Written by shubham.bhusate

Last published at: December 23rd, 2024

Problem

When you try to run a Python UDF without EXECUTE permission, the UDF fails.  

 

‘User does not have EXECUTE on Routine or Model '<your-catalog>.<your-schema>.<your-function>'

 

Cause

Databricks strictly enforces EXECUTE permissions on Python UDFs. Only authorized users can run UDFs.

Python UDFs are able to perform complex, resource-intensive operations, such as custom logic and external API calls, which go beyond the scope of SQL UDFs. Strong controls on this complexity allow your organization to better manage the increased potential for security and stability risks. Better management enhances system security and governance. 

 

Solution

The function owner needs to grant EXECUTE permission for a Python UDF to a user or user group.

 

User

GRANT EXECUTE ON FUNCTION <your-catalog>.<your-schema>.<your-function> TO <user-email>;

 

Group

GRANT EXECUTE ON FUNCTION <your-catalog>.<your-schema>.<your-function> TO <group-name>