diff --git a/CHANGES.rst b/CHANGES.rst index 668e6394..00d15408 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,7 +4,13 @@ Changelog Here you can see the full list of changes between each SQLAlchemy-Continuum release. -1.1.0 (2014-09-xx) +1.1.1 (2014-10-07) +^^^^^^^^^^^^^^^^^^ + +- Fixed native versioning trigger syncing + + +1.1.0 (2014-10-02) ^^^^^^^^^^^^^^^^^^ - Added Python 3.4 to test suite @@ -17,6 +23,7 @@ Here you can see the full list of changes between each SQLAlchemy-Continuum rele - Fixed version model building when no versioned models were found (previously threw AttributeError) - Replaced plugin template methods before_create_tx_object and after_create_tx_object with transaction_args to better cope with native versioning + 1.0.3 (2014-07-16) ^^^^^^^^^^^^^^^^^^ diff --git a/setup.py b/setup.py index bf800d93..d23e3ed2 100644 --- a/setup.py +++ b/setup.py @@ -49,7 +49,7 @@ def run(self): setup( name='SQLAlchemy-Continuum', - version='1.1.0', + version='1.1.1', url='https://github.com/kvesteri/sqlalchemy-continuum', license='BSD', author='Konsta Vesterinen', diff --git a/sqlalchemy_continuum/__init__.py b/sqlalchemy_continuum/__init__.py index 3ca605ce..850a3347 100644 --- a/sqlalchemy_continuum/__init__.py +++ b/sqlalchemy_continuum/__init__.py @@ -18,7 +18,7 @@ ) -__version__ = '1.1.0' +__version__ = '1.1.1' versioning_manager = VersioningManager() @@ -69,12 +69,6 @@ def make_versioned( 'before_cursor_execute', manager.track_association_operations ) - if manager.options['native_versioning']: - sa.event.listen( - sa.pool.Pool, - 'connect', - manager.on_connect - ) def remove_versioning( @@ -102,9 +96,3 @@ def remove_versioning( 'before_cursor_execute', manager.track_association_operations ) - if manager.options['native_versioning']: - sa.event.remove( - sa.pool.Pool, - 'connect', - manager.on_connect - ) diff --git a/sqlalchemy_continuum/dialects/postgresql.py b/sqlalchemy_continuum/dialects/postgresql.py index 1843e4ee..51567585 100644 --- a/sqlalchemy_continuum/dialects/postgresql.py +++ b/sqlalchemy_continuum/dialects/postgresql.py @@ -50,7 +50,11 @@ CREATE OR REPLACE FUNCTION {procedure_name}() RETURNS TRIGGER AS $$ DECLARE transaction_id_value INT; BEGIN - transaction_id_value = (SELECT id FROM temporary_transaction); + BEGIN + transaction_id_value = (SELECT id FROM temporary_transaction); + EXCEPTION WHEN others THEN + RETURN NEW; + END; IF transaction_id_value IS NULL THEN RETURN NEW; END IF; @@ -483,7 +487,7 @@ def sync_trigger(conn, table_name): set(c.name for c in parent_table.c) - set(c.name for c in version_table.c if not c.name.endswith('_mod')) ) - drop_trigger(conn, table_name) + drop_trigger(conn, parent_table.name) create_trigger(conn, table=parent_table, excluded_columns=excluded_columns) @@ -512,7 +516,7 @@ def create_trigger( def drop_trigger(conn, table_name): - conn.execute('DROP FUNCTION IF EXISTS %s_audit()' % table_name) conn.execute( 'DROP TRIGGER IF EXISTS %s_trigger ON %s' % (table_name, table_name) ) + conn.execute('DROP FUNCTION IF EXISTS %s_audit()' % table_name) diff --git a/sqlalchemy_continuum/manager.py b/sqlalchemy_continuum/manager.py index 6c81b052..48a7ea91 100644 --- a/sqlalchemy_continuum/manager.py +++ b/sqlalchemy_continuum/manager.py @@ -313,14 +313,6 @@ def unit_of_work(self, session): self.units_of_work[conn] = uow return uow - def on_connect(self, dbapi_conn, connection_record): - from .dialects.postgresql import CreateTemporaryTransactionTableSQL - - cursor = dbapi_conn.cursor() - cursor.execute(str(CreateTemporaryTransactionTableSQL())) - dbapi_conn.commit() - cursor.close() - def before_flush(self, session, flush_context, instances): """ Before flush listener for SQLAlchemy sessions. If this manager has diff --git a/tests/dialects/test_triggers.py b/tests/dialects/test_triggers.py index bd7ff92b..dde5a045 100644 --- a/tests/dialects/test_triggers.py +++ b/tests/dialects/test_triggers.py @@ -43,12 +43,13 @@ def teardown_method(self, method): def test_sync_triggers(self): sync_trigger(self.connection, 'article_version') - assert 'DROP FUNCTION ' in QueryPool.queries[-4] - assert 'DROP TRIGGER ' in QueryPool.queries[-3] + assert 'DROP TRIGGER ' in QueryPool.queries[-4] + assert 'DROP FUNCTION ' in QueryPool.queries[-3] assert 'CREATE OR REPLACE FUNCTION ' in QueryPool.queries[-2] assert 'CREATE TRIGGER ' in QueryPool.queries[-1] + sync_trigger(self.connection, 'article_version') def test_drop_triggers(self): drop_trigger(self.connection, 'article') - assert 'DROP FUNCTION ' in QueryPool.queries[-2] - assert 'DROP TRIGGER ' in QueryPool.queries[-1] + assert 'DROP TRIGGER ' in QueryPool.queries[-2] + assert 'DROP FUNCTION ' in QueryPool.queries[-1]