0

For the context: I am using a Postgres RDS which comes with some infinite timestamp for some default roles. Alembic (or more precisely, psycopg) does not like that at all. My first revision is updating some those timestamps to something legit (aka year 9999).

The thing is that I test on docker first, where those roles do not exist. This makes the migration fail, and I would like to recover cleanly (ie. ignore it).

What I would like is:

from psycopg.errors import UndefinedObject

try:
    op.execute("alter role pgsqladmin valid until '9999-12-31 12:00:00 +0'")
except sa.exc.ProgrammingError as e:
    if isinstance(e.__context__, UndefinedObject):
        print("I don't care!")
        op.rollback() # That's where I do not know what to have
    else:
        raise

But I cannot find a relevant line to replace the invalid op.rollback. Is it at all possible?

And yes, I am aware I could first check if the role does exist instead of try/excepting it or find other workarounds, but I would prefer this solution if possible.

python_user
  • 5,375
  • 2
  • 13
  • 32
Guillaume
  • 2,325
  • 2
  • 22
  • 40

0 Answers0