python - Peewee: Outer transaction does not roll back inner transaction (savepoints) -


running following python script twice throws error:

peewee.programmingerror: relation "test_table" exists 

because table not removed on .rollback(). removing inner transaction (with test_db.atomic()) works. why inner transaction (which savepoints according documentation) not rolled back?

from datetime import datetime peewee import model, datetimefield playhouse.postgres_ext import postgresqlextdatabase  """ create role test login; drop database if exists test; create database test owner test; """  credentials = {     "database": "test",     "user": "test",     "password": none,     "host": "localhost",     "port": 5432,     "register_hstore": false, }   test_db = postgresqlextdatabase(**credentials) test_db.connect() test_db.set_autocommit(false) test_db.begin()  # start transaction  class testtable(model):     timestamp = datetimefield(null=false, default=datetime(1970,1,1,0,0,0,))      class meta:         db_table = "test_table"         database = test_db  test_db.atomic():      testtable.create_table()     testtable.create()  test_db.rollback()  # rollback transaction  print testtable.get().timestamp test_db.close() 

versions

peewee==2.8.3 psycopg2==2.6.2  postgresql 9.5.1 on x86_64-apple-darwin15.3.0, compiled apple llvm version 7.0.2 (clang-700.1.81), 64-bit 

depending on database you're using, ddl (schema changes) may or may not possible rollback.

postgresql , sqlite both appear support rolling ddl, mysql not.

however, python driver sqlite has bug causes emit commit when issue ddl. first patch submitted in 2010: http://bugs.python.org/issue10740 .

also take @ pysqlite2, same standard-library sqlite3:

https://github.com/ghaering/pysqlite/blob/ca5dc55b462a7e67072205bb1a9a0f62a7c6efc4/src/cursor.c#l537-l547


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -