diff --git a/zun/db/sqlalchemy/alembic/versions/33cdd98bb9b2_split_volume_mapping_table.py b/zun/db/sqlalchemy/alembic/versions/33cdd98bb9b2_split_volume_mapping_table.py index 97a3c46a4..2762e87ad 100644 --- a/zun/db/sqlalchemy/alembic/versions/33cdd98bb9b2_split_volume_mapping_table.py +++ b/zun/db/sqlalchemy/alembic/versions/33cdd98bb9b2_split_volume_mapping_table.py @@ -92,8 +92,7 @@ def update_existing_records(): nullable=True)) # perform data migration between tables - session = sa.orm.Session(bind=op.get_bind()) - with session.begin(subtransactions=True): + with sa.orm.Session(bind=op.get_bind()) as session: for row in session.query(VOLUME_MAPPING_TABLE): res = session.execute( VOLUME_TABLE.insert().values( @@ -112,8 +111,8 @@ def update_existing_records(): volume_id=res.inserted_primary_key[0]).where( VOLUME_MAPPING_TABLE.c.id == row.id) ) - # this commit is necessary to allow further operations - session.commit() + # this commit is necessary to allow further operations + session.commit() op.alter_column('volume_mapping', 'volume_id', nullable=False, diff --git a/zun/db/sqlalchemy/alembic/versions/3e80bbfd8da7_convert_type_of_command_from_string_to_.py b/zun/db/sqlalchemy/alembic/versions/3e80bbfd8da7_convert_type_of_command_from_string_to_.py index 4ee5cdcc5..20056e469 100644 --- a/zun/db/sqlalchemy/alembic/versions/3e80bbfd8da7_convert_type_of_command_from_string_to_.py +++ b/zun/db/sqlalchemy/alembic/versions/3e80bbfd8da7_convert_type_of_command_from_string_to_.py @@ -43,8 +43,7 @@ TABLE_MODEL = sa.Table( def upgrade(): op.alter_column('container', 'command', type_=sa.Text()) # Convert 'command' from string to json-encoded list - session = sa.orm.Session(bind=op.get_bind()) - with session.begin(subtransactions=True): + with sa.orm.Session(bind=op.get_bind()) as session: for row in session.query(TABLE_MODEL): if row[1]: command = shlex.split(row[1]) @@ -53,4 +52,4 @@ def upgrade(): TABLE_MODEL.update().values( command=command).where( TABLE_MODEL.c.id == row[0])) - session.commit() + session.commit() diff --git a/zun/db/sqlalchemy/alembic/versions/d502ce8fb705_add_rp_uuid_to_compute_node.py b/zun/db/sqlalchemy/alembic/versions/d502ce8fb705_add_rp_uuid_to_compute_node.py index 80cfcee7d..ee213094d 100644 --- a/zun/db/sqlalchemy/alembic/versions/d502ce8fb705_add_rp_uuid_to_compute_node.py +++ b/zun/db/sqlalchemy/alembic/versions/d502ce8fb705_add_rp_uuid_to_compute_node.py @@ -41,16 +41,15 @@ def upgrade(): 'compute_node', ['rp_uuid']) # perform data migration between tables - session = sa.orm.Session(bind=op.get_bind()) - with session.begin(subtransactions=True): + with sa.orm.Session(bind=op.get_bind()) as session: for row in session.query(COMPUTE_NODE_TABLE): session.execute( COMPUTE_NODE_TABLE.update().values( rp_uuid=row.uuid).where( COMPUTE_NODE_TABLE.c.uuid == row.uuid) ) - # this commit is necessary to allow further operations - session.commit() + # this commit is necessary to allow further operations + session.commit() op.alter_column('compute_node', 'rp_uuid', nullable=False, diff --git a/zun/db/sqlalchemy/api.py b/zun/db/sqlalchemy/api.py index 38f6155bf..d80860dab 100644 --- a/zun/db/sqlalchemy/api.py +++ b/zun/db/sqlalchemy/api.py @@ -760,7 +760,8 @@ class Connection(object): query = model_query(models.Inventory, session=session) query = self._add_inventories_filters(query, filters) query = query.join(models.Inventory.resource_provider) - query = query.options(contains_eager('resource_provider')) + query = query.options( + contains_eager(models.Inventory.resource_provider)) return _paginate_query(models.Inventory, limit, marker, sort_key, sort_dir, query) @@ -783,7 +784,8 @@ class Connection(object): session = get_session() query = model_query(models.Inventory, session=session) query = query.join(models.Inventory.resource_provider) - query = query.options(contains_eager('resource_provider')) + query = query.options( + contains_eager(models.Inventory.resource_provider)) query = query.filter_by(id=inventory_id) try: return query.one() @@ -825,7 +827,8 @@ class Connection(object): query = model_query(models.Allocation, session=session) query = self._add_allocations_filters(query, filters) query = query.join(models.Allocation.resource_provider) - query = query.options(contains_eager('resource_provider')) + query = query.options( + contains_eager(models.Allocation.resource_provider)) return _paginate_query(models.Allocation, limit, marker, sort_key, sort_dir, query) @@ -846,7 +849,8 @@ class Connection(object): with session.begin(): query = model_query(models.Allocation, session=session) query = query.join(models.Allocation.resource_provider) - query = query.options(contains_eager('resource_provider')) + query = query.options( + contains_eager(models.Allocation.resource_provider)) query = query.filter_by(id=allocation_id) try: return query.one()