<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Dynamic GRANT in Warehousing &amp; Analytics</title>
    <link>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/121791#M2122</link>
    <description>&lt;P&gt;I use notebooks as part of the asset bundle deployment to conduct a lot of dynamic configurations based upon the workspace being deployed to (ex. Development, Test, Production).&amp;nbsp; In conjunction, I developed a helper Python library with a number of functions that are used with administrative tasks.&amp;nbsp; Attached is the one I created for adding schema permissions.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from typing import Tuple
import re

def addSchemaPermissions(schemaName: str, principal: str, permissionList: str, clearAll: bool) -&amp;gt; Tuple[bool, str]:

    try:
        if clearAll:
            spark.sql(f"REVOKE ALL PRIVILEGES ON SCHEMA {schemaName} FROM `{principal}`")

        spark.sql(f"GRANT {permissionList} ON SCHEMA {schemaName} TO `{principal}`")
        return True, ""
    
    except Exception as e:
        fullErrorMessage = str(e)

        # Try to extract the Databricks error class and readable message
        errorClassMatch = re.search(r"ErrorClass=([A-Z_\.]+)", fullErrorMessage)
        mainMessageMatch = re.search(r"] (.+?)\\n", fullErrorMessage)

        errorClass = errorClassMatch.group(1) if errorClassMatch else "Unknown Error"
        mainMessage = mainMessageMatch.group(1) if mainMessageMatch else fullErrorMessage.splitlines()[0]

        return False, f"{errorClass}: {mainMessage}"

success, errorMessage = addSchemaPermissions('your_catalog_name.your_schema_name', 'Your Principal Name', 'USE SCHEMA, SELECT', True)

if not success:
    print(f"Failed to update schema permissions: {errorMessage}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 14 Jun 2025 20:57:39 GMT</pubDate>
    <dc:creator>jameshughes</dc:creator>
    <dc:date>2025-06-14T20:57:39Z</dc:date>
    <item>
      <title>Dynamic GRANT</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/113880#M1969</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am struggling trying to assign permission dynamically on a schema. I am using databricks asset bundle and I have a parametrized script to assign permission.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;grant select on schema {{schema}} to {{group}};&lt;/LI-CODE&gt;&lt;P&gt;I cannot achieve a dynamic grant statement. I also tried running on a notebook something like&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;execute immediate 'grant select on schema ? to ?' using ('my_schema', '`my_group`');&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;but unfortunately this does not work. From docs it seems it can be achievable with IDENTIFUER clause, I tried also that but without success. It throws syntax error.&lt;/P&gt;&lt;P&gt;It this achievable in some way or not? Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Mar 2025 11:31:15 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/113880#M1969</guid>
      <dc:creator>jackintosh</dc:creator>
      <dc:date>2025-03-28T11:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic GRANT</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/120688#M2085</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;It seems that IDENTIFIER is not supported with GRANT at the moment, however internal teams are working on supporting this.&lt;/P&gt;
&lt;P&gt;Thus, as a temporary workaround, I believe you can use the following as you have already been using -&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;grant select on schema {{schema}} to {{group}};&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jun 2025 07:23:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/120688#M2085</guid>
      <dc:creator>Vidhi_Khaitan</dc:creator>
      <dc:date>2025-06-02T07:23:30Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic GRANT</title>
      <link>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/121791#M2122</link>
      <description>&lt;P&gt;I use notebooks as part of the asset bundle deployment to conduct a lot of dynamic configurations based upon the workspace being deployed to (ex. Development, Test, Production).&amp;nbsp; In conjunction, I developed a helper Python library with a number of functions that are used with administrative tasks.&amp;nbsp; Attached is the one I created for adding schema permissions.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from typing import Tuple
import re

def addSchemaPermissions(schemaName: str, principal: str, permissionList: str, clearAll: bool) -&amp;gt; Tuple[bool, str]:

    try:
        if clearAll:
            spark.sql(f"REVOKE ALL PRIVILEGES ON SCHEMA {schemaName} FROM `{principal}`")

        spark.sql(f"GRANT {permissionList} ON SCHEMA {schemaName} TO `{principal}`")
        return True, ""
    
    except Exception as e:
        fullErrorMessage = str(e)

        # Try to extract the Databricks error class and readable message
        errorClassMatch = re.search(r"ErrorClass=([A-Z_\.]+)", fullErrorMessage)
        mainMessageMatch = re.search(r"] (.+?)\\n", fullErrorMessage)

        errorClass = errorClassMatch.group(1) if errorClassMatch else "Unknown Error"
        mainMessage = mainMessageMatch.group(1) if mainMessageMatch else fullErrorMessage.splitlines()[0]

        return False, f"{errorClass}: {mainMessage}"

success, errorMessage = addSchemaPermissions('your_catalog_name.your_schema_name', 'Your Principal Name', 'USE SCHEMA, SELECT', True)

if not success:
    print(f"Failed to update schema permissions: {errorMessage}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jun 2025 20:57:39 GMT</pubDate>
      <guid>https://community.databricks.com/t5/warehousing-analytics/dynamic-grant/m-p/121791#M2122</guid>
      <dc:creator>jameshughes</dc:creator>
      <dc:date>2025-06-14T20:57:39Z</dc:date>
    </item>
  </channel>
</rss>

