Closed JayArbo closed 5 years ago
Hi @JayArbo, I think that what's happening here is that your except
block is swallowing the exception. I tried running:
import pg8000
connection = pg8000.connect("postgres", host='localhost', database="postgres")
connection.autocommit = True
cursor = connection.cursor()
cursor.execute("CREATE ROLE pythonuser2 PASSWORD 'password' LOGIN")
connection.close()
And this does indeed raise an exception the second time it's run.
postgres raises an error if you try to create a role that already exists.. pg8000 doesn't report this error. sample below...
import pg8000 from sys import exc_info
connection = pg8000.connect("postgres", host='localhost', database="postgres") connection.autocommit = True cursor = connection.cursor() cmd = "CREATE ROLE %s PASSWORD '%s' LOGIN" % ("pythonuser2", "password") try:
doesn't raise exception when user already exists
except: e = exc_info()[1] #never executes connection.autocommit = False
connection.close