SQLalchemy not creating constraint for Enum on version 1.4.0+
SQLachemy was upgraded via the `requirements` projects commit
(dc86260b28
).
That upgrade broke some code. Therefore, this patch intends to fix
the code that was broken due to a method removal and also due to a
change in `create_constraint` for Enum types, which was defaulted
to `False` in version 1.4.0
Change-Id: Ib36a7275ce8ff30aa19cbde521fd37f60bd00ff8
This commit is contained in:
parent
510d8bf564
commit
35ce237b76
@ -45,7 +45,7 @@ class State(api.State):
|
||||
models.StateInfo,
|
||||
session)
|
||||
q = q.filter(models.StateInfo.name == name)
|
||||
q = q.with_lockmode('update')
|
||||
q = q.with_for_update()
|
||||
db_state = q.one()
|
||||
db_state.state = state
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
@ -70,7 +70,7 @@ class State(api.State):
|
||||
models.StateInfo,
|
||||
session)
|
||||
q = q.filter(models.StateInfo.name == name)
|
||||
q = q.with_lockmode('update')
|
||||
q = q.with_for_update()
|
||||
db_state = q.one()
|
||||
db_state.s_metadata = metadata
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
@ -103,7 +103,7 @@ class ModuleInfo(api.ModuleInfo):
|
||||
session)
|
||||
q = q.filter(
|
||||
models.ModuleStateInfo.name == name)
|
||||
q = q.with_lockmode('update')
|
||||
q = q.with_for_update()
|
||||
db_state = q.one()
|
||||
db_state.priority = priority
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
@ -132,7 +132,7 @@ class ModuleInfo(api.ModuleInfo):
|
||||
models.ModuleStateInfo,
|
||||
session)
|
||||
q = q.filter(models.ModuleStateInfo.name == name)
|
||||
q = q.with_lockmode('update')
|
||||
q = q.with_for_update()
|
||||
db_state = q.one()
|
||||
db_state.state = state
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
@ -165,7 +165,7 @@ class ServiceToCollectorMapping(object):
|
||||
session)
|
||||
q = q.filter(
|
||||
models.ServiceToCollectorMapping.service == service)
|
||||
q = q.with_lockmode('update')
|
||||
q = q.with_for_update()
|
||||
db_mapping = q.one()
|
||||
db_mapping.collector = collector
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
|
@ -238,7 +238,7 @@ class HashMapMapping(Base, HashMapBase):
|
||||
sqlalchemy.Enum(
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_map_type'),
|
||||
name='enum_map_type', create_constraint=True),
|
||||
nullable=False)
|
||||
service_id = sqlalchemy.Column(
|
||||
sqlalchemy.Integer,
|
||||
@ -310,7 +310,7 @@ class HashMapThreshold(Base, HashMapBase):
|
||||
sqlalchemy.Enum(
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_hashmap_type'),
|
||||
name='enum_hashmap_type', create_constraint=True),
|
||||
nullable=False)
|
||||
service_id = sqlalchemy.Column(
|
||||
sqlalchemy.Integer,
|
||||
|
@ -75,8 +75,8 @@ def upgrade():
|
||||
sa.Column('cost', sa.Numeric(20, 8), nullable=False),
|
||||
sa.Column(
|
||||
'map_type',
|
||||
sa.Enum('flat', 'rate', name='enum_map_type'),
|
||||
nullable=False),
|
||||
sa.Enum('flat', 'rate', name='enum_map_type',
|
||||
create_constraint=True), nullable=False),
|
||||
sa.Column('service_id', sa.Integer(), nullable=True),
|
||||
sa.Column('field_id', sa.Integer(), nullable=True),
|
||||
sa.Column('group_id', sa.Integer(), nullable=True),
|
||||
|
@ -75,7 +75,8 @@ def get_reflect(table):
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_{}map_type'.format(
|
||||
'hash' if table == 'hashmap_thresholds' else '')),
|
||||
'hash' if table == 'hashmap_thresholds' else ''),
|
||||
create_constraint=True),
|
||||
nullable=False)]
|
||||
return reflect_args
|
||||
|
||||
|
@ -42,8 +42,8 @@ def upgrade():
|
||||
sa.Column('cost', sa.Numeric(precision=20, scale=8), nullable=False),
|
||||
sa.Column(
|
||||
'map_type',
|
||||
sa.Enum('flat', 'rate', name='enum_map_type'),
|
||||
nullable=False),
|
||||
sa.Enum('flat', 'rate', name='enum_map_type',
|
||||
create_constraint=True), nullable=False),
|
||||
sa.Column('service_id', sa.Integer(), nullable=True),
|
||||
sa.Column('field_id', sa.Integer(), nullable=True),
|
||||
sa.Column('group_id', sa.Integer(), nullable=True),
|
||||
|
@ -40,8 +40,8 @@ def create_table(is_old=False):
|
||||
sa.Column('cost', sa.Numeric(precision=20, scale=8), nullable=False),
|
||||
sa.Column(
|
||||
'map_type',
|
||||
sa.Enum('flat', 'rate', name='enum_map_type'),
|
||||
nullable=False),
|
||||
sa.Enum('flat', 'rate', name='enum_map_type',
|
||||
create_constraint=True), nullable=False),
|
||||
sa.Column('service_id', sa.Integer(), nullable=True),
|
||||
sa.Column('field_id', sa.Integer(), nullable=True),
|
||||
sa.Column('group_id', sa.Integer(), nullable=True),
|
||||
|
@ -78,7 +78,8 @@ def get_reflect(table):
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_{}map_type'.format(
|
||||
'hash' if table == 'hashmap_thresholds' else '')),
|
||||
'hash' if table == 'hashmap_thresholds' else ''),
|
||||
create_constraint=True),
|
||||
nullable=False)]
|
||||
return reflect_args
|
||||
|
||||
|
@ -401,7 +401,7 @@ class HashMap(api.HashMap):
|
||||
q = session.query(models.HashMapMapping)
|
||||
q = q.filter(
|
||||
models.HashMapMapping.mapping_id == uuid)
|
||||
mapping_db = q.with_lockmode('update').one()
|
||||
mapping_db = q.with_for_update().one()
|
||||
if kwargs:
|
||||
# NOTE(sheeprine): We want to check that value is not set
|
||||
# to a None value.
|
||||
@ -448,7 +448,7 @@ class HashMap(api.HashMap):
|
||||
q = session.query(models.HashMapThreshold)
|
||||
q = q.filter(
|
||||
models.HashMapThreshold.threshold_id == uuid)
|
||||
threshold_db = q.with_lockmode('update').one()
|
||||
threshold_db = q.with_for_update().one()
|
||||
if kwargs:
|
||||
# Resolve FK
|
||||
if 'group_id' in kwargs:
|
||||
@ -516,7 +516,7 @@ class HashMap(api.HashMap):
|
||||
q = q.filter(models.HashMapGroup.group_id == uuid)
|
||||
with session.begin():
|
||||
try:
|
||||
r = q.with_lockmode('update').one()
|
||||
r = q.with_for_update().one()
|
||||
except sqlalchemy.orm.exc.NoResultFound:
|
||||
raise api.NoSuchGroup(uuid=uuid)
|
||||
if recurse:
|
||||
|
@ -236,7 +236,7 @@ class HashMapMapping(Base, HashMapBase):
|
||||
sqlalchemy.Enum(
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_map_type'),
|
||||
name='enum_map_type', create_constraint=True),
|
||||
nullable=False)
|
||||
service_id = sqlalchemy.Column(
|
||||
sqlalchemy.Integer,
|
||||
@ -315,7 +315,7 @@ class HashMapThreshold(Base, HashMapBase):
|
||||
sqlalchemy.Enum(
|
||||
'flat',
|
||||
'rate',
|
||||
name='enum_hashmap_type'),
|
||||
name='enum_hashmap_type', create_constraint=True),
|
||||
nullable=False)
|
||||
service_id = sqlalchemy.Column(
|
||||
sqlalchemy.Integer,
|
||||
|
@ -80,7 +80,7 @@ class PyScripts(api.PyScripts):
|
||||
q = q.filter(
|
||||
models.PyScriptsScript.script_id == uuid
|
||||
)
|
||||
script_db = q.with_lockmode('update').one()
|
||||
script_db = q.with_for_update().one()
|
||||
if kwargs:
|
||||
excluded_cols = ['script_id']
|
||||
for col in excluded_cols:
|
||||
|
Loading…
Reference in New Issue
Block a user