@@ -117,20 +117,17 @@ def create_masked_role(role_name, inherit_from=None):
117117 # Always ensure the role has proper permissions to django_postgres_anon tables
118118 # This is needed for the role to access the app's models even when switching contexts
119119 django_postgres_anon_tables = [
120- ' django_postgres_anon_maskingrule' ,
121- ' django_postgres_anon_maskingpreset' ,
122- ' django_postgres_anon_maskingpreset_rules' ,
123- ' django_postgres_anon_maskedrole' ,
124- ' django_postgres_anon_maskinglog'
120+ " django_postgres_anon_maskingrule" ,
121+ " django_postgres_anon_maskingpreset" ,
122+ " django_postgres_anon_maskingpreset_rules" ,
123+ " django_postgres_anon_maskedrole" ,
124+ " django_postgres_anon_maskinglog" ,
125125 ]
126126
127127 for table in django_postgres_anon_tables :
128128 try :
129129 # Check if table exists first
130- cursor .execute (
131- "SELECT 1 FROM information_schema.tables WHERE table_name = %s" ,
132- [table ]
133- )
130+ cursor .execute ("SELECT 1 FROM information_schema.tables WHERE table_name = %s" , [table ])
134131 if cursor .fetchone ():
135132 # Grant SELECT permissions on django_postgres_anon tables
136133 cursor .execute (
@@ -139,7 +136,7 @@ def create_masked_role(role_name, inherit_from=None):
139136
140137 # For the MaskedRole table, also grant INSERT and UPDATE permissions
141138 # so roles can update their own status
142- if table == ' django_postgres_anon_maskedrole' :
139+ if table == " django_postgres_anon_maskedrole" :
143140 try :
144141 cursor .execute (
145142 f"GRANT INSERT, UPDATE ON TABLE { connection .ops .quote_name (table )} TO { connection .ops .quote_name (role_name )} "
@@ -148,7 +145,9 @@ def create_masked_role(role_name, inherit_from=None):
148145 cursor .execute (
149146 f"GRANT USAGE ON SEQUENCE { connection .ops .quote_name (table + '_id_seq' )} TO { connection .ops .quote_name (role_name )} "
150147 )
151- logger .debug (f"Granted INSERT, UPDATE, and USAGE on sequence for { table } to { role_name } " )
148+ logger .debug (
149+ f"Granted INSERT, UPDATE, and USAGE on sequence for { table } to { role_name } "
150+ )
152151 except Exception as write_error :
153152 logger .warning (f"Failed to grant write permissions on { table } : { write_error } " )
154153
@@ -160,7 +159,9 @@ def create_masked_role(role_name, inherit_from=None):
160159
161160 # Grant CONNECT permission on database
162161 try :
163- cursor .execute (f"GRANT CONNECT ON DATABASE { connection .ops .quote_name (connection .settings_dict ['NAME' ])} TO { connection .ops .quote_name (role_name )} " )
162+ cursor .execute (
163+ f"GRANT CONNECT ON DATABASE { connection .ops .quote_name (connection .settings_dict ['NAME' ])} TO { connection .ops .quote_name (role_name )} "
164+ )
164165 logger .debug (f"Granted CONNECT on database to { role_name } " )
165166 except Exception as db_error :
166167 logger .warning (f"Failed to grant CONNECT permission: { db_error } " )
@@ -373,7 +374,7 @@ def switch_to_role(role_name: str, auto_create: bool = True):
373374 cursor .execute (f"SET ROLE { role_name } " )
374375
375376 # For masked roles, also set the search path to prioritize mask schema
376- if ' mask' in role_name .lower ():
377+ if " mask" in role_name .lower ():
377378 cursor .execute ("SET search_path = mask, public" )
378379 logger .debug (f"Set search_path to 'mask, public' for role { role_name } " )
379380
0 commit comments