Do not use strings as attributes for loader

With SQLalchemy 2.0 strings are no longer accepted as attributes for
the loader and attributes must be used instead directly.

This also fixes DB migrations by removing deprecated subtransactions.

Change-Id: I94865b90701e5a51f69187d9e790386e29ad7b5a
This commit is contained in:
Dmitriy Rabotyagov 2024-09-24 21:21:33 +02:00
parent c05fe096cd
commit 2681091ffa
4 changed files with 16 additions and 15 deletions

View File

@ -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(

View File

@ -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])

View File

@ -41,8 +41,7 @@ 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(

View File

@ -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()