stvnnnnnn commited on
Commit
9187593
·
verified ·
1 Parent(s): 46d6b1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -198,7 +198,7 @@ class PostgresManager:
198
 
199
  upper = stmt.upper()
200
 
201
- # Saltar cosas peligrosas o globales
202
  skip_prefixes = (
203
  "SET ",
204
  "SELECT PG_CATALOG.SET_CONFIG",
@@ -215,7 +215,19 @@ class PostgresManager:
215
  if upper.startswith(skip_prefixes):
216
  return
217
 
218
- # Quitar ';' final (psycopg2 no la necesita)
 
 
 
 
 
 
 
 
 
 
 
 
219
  if stmt.endswith(";"):
220
  stmt = stmt[:-1]
221
 
@@ -223,7 +235,7 @@ class PostgresManager:
223
  cur.execute(stmt)
224
  except Exception as e:
225
  msg = str(e).lower()
226
- # Ignorar cosas no fatales típicas de dumps
227
  if "already exists" in msg or "duplicate key value" in msg:
228
  print("[WARN] Ignorando error no crítico:", e)
229
  return
 
198
 
199
  upper = stmt.upper()
200
 
201
+ # 1) Saltar cosas peligrosas o globales
202
  skip_prefixes = (
203
  "SET ",
204
  "SELECT PG_CATALOG.SET_CONFIG",
 
215
  if upper.startswith(skip_prefixes):
216
  return
217
 
218
+ # 2) Saltar cualquier sentencia que intente cambiar OWNER o ROLES
219
+ # Ejemplos:
220
+ # ALTER TABLE ... OWNER TO postgres;
221
+ # ALTER FUNCTION ... OWNER TO postgres;
222
+ # CREATE ROLE postgres;
223
+ # ALTER ROLE postgres ...;
224
+ # SET ROLE postgres;
225
+ if " OWNER TO " in upper:
226
+ return
227
+ if upper.startswith("CREATE ROLE") or upper.startswith("ALTER ROLE") or upper.startswith("SET ROLE"):
228
+ return
229
+
230
+ # 3) Quitar ';' final (psycopg2 no la necesita)
231
  if stmt.endswith(";"):
232
  stmt = stmt[:-1]
233
 
 
235
  cur.execute(stmt)
236
  except Exception as e:
237
  msg = str(e).lower()
238
+ # Ignorar errores típicos de dumps (idempotencia)
239
  if "already exists" in msg or "duplicate key value" in msg:
240
  print("[WARN] Ignorando error no crítico:", e)
241
  return