From 0e0904580b692655b818e1df155aae1031cc5025 Mon Sep 17 00:00:00 2001 From: Felix Wu Date: Tue, 26 Apr 2022 11:44:32 -0700 Subject: [PATCH] catch setting role exception and output a warning instead of stop migration process --- aiven_db_migrate/migrate/pgmigrate.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/aiven_db_migrate/migrate/pgmigrate.py b/aiven_db_migrate/migrate/pgmigrate.py index 4984b10..b024f6a 100644 --- a/aiven_db_migrate/migrate/pgmigrate.py +++ b/aiven_db_migrate/migrate/pgmigrate.py @@ -992,18 +992,21 @@ def _migrate_roles(self) -> Dict[str, PGRoleTask]: message=err.diag.message_primary, ) else: - if role.rolconfig: - for conf in role.rolconfig: - key, value = conf.split("=", 1) - self.log.info("Setting config for role %r: %s = %s", role.rolname, key, value) - self.target.c(f'ALTER ROLE {role.safe_rolname} SET "{key}" = %s', args=(value, ), return_rows=0) - roles[role.rolname] = PGRoleTask( - rolname=rolname, - rolpassword=role.rolpassword, - status=PGRoleStatus.created, - message="role created", - ) - + try: + if role.rolconfig: + for conf in role.rolconfig: + key, value = conf.split("=", 1) + self.log.info("Setting config for role %r: %s = %s", role.rolname, key, value) + self.target.c(f'ALTER ROLE {role.safe_rolname} SET "{key}" = %s', args=(value, ), return_rows=0) + roles[role.rolname] = PGRoleTask( + rolname=rolname, + rolpassword=role.rolpassword, + status=PGRoleStatus.created, + message="role created", + ) + # display warning when ProgrammingErrorERROR 42501: InsufficientPrivilege: permission denied to set parameter for a role + except psycopg2.errors.InsufficientPrivilege: + self.log.warning(f'Setting config [{role.rolname}]: [{key}] = [{value}] failed. psycopg2.errors.InsufficientPrivilege') return roles @staticmethod