Skip to content

Commit 8a0f4c0

Browse files
committed
no error if schema does not exist when granting roles
1 parent b9ae2a1 commit 8a0f4c0

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pum/role_manager.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ def grant(
5454
raise ValueError("Schemas must be defined for the permission.")
5555

5656
for schema in self.schemas:
57+
# Detect if schema exists; if not, warn and continue
58+
cursor = SqlContent("SELECT 1 FROM pg_namespace WHERE nspname = {schema}").execute(
59+
connection=connection,
60+
commit=False,
61+
parameters={"schema": psycopg.sql.Literal(schema)},
62+
)
63+
if cursor.fetchone() is None:
64+
logger.warning(
65+
f"Schema {schema} does not exist; skipping grant of {self.type.value} "
66+
f"permission to role {role}."
67+
)
68+
continue
69+
5770
logger.debug(
5871
f"Granting {self.type.value} permission on schema {schema} to role {role}."
5972
)

0 commit comments

Comments
 (0)