Fix oslo.db >= 15.0.0 compatibility
Minimal refactor of SQLAlchemy api module to be compatible with oslo.db >= 15.0.0 where autocommit behaviour was dropped. Closes-Bug: #2056181 Change-Id: I33be53f647faae2aad30a43c10980df950d5d7c2 (cherry picked from commit bc5922c68482e54137d33913f2ed416a164e9f3b)
This commit is contained in:
parent
9d58a6d457
commit
6b433b3547
@ -44,11 +44,7 @@ _FACADE = None
|
||||
def _create_facade_lazily():
|
||||
global _FACADE
|
||||
if _FACADE is None:
|
||||
# FIXME(amoralej): Remove autocommit=True (and ideally use of
|
||||
# LegacyEngineFacade) asap since it's not compatible with SQLAlchemy
|
||||
# 2.0.
|
||||
_FACADE = db_session.EngineFacade.from_config(CONF,
|
||||
autocommit=True)
|
||||
_FACADE = db_session.EngineFacade.from_config(CONF)
|
||||
return _FACADE
|
||||
|
||||
|
||||
@ -252,15 +248,20 @@ class Connection(api.BaseConnection):
|
||||
return query
|
||||
|
||||
def _create(self, model, values):
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
obj = model()
|
||||
cleaned_values = {k: v for k, v in values.items()
|
||||
if k not in self._get_relationships(model)}
|
||||
obj.update(cleaned_values)
|
||||
obj.save()
|
||||
obj.save(session=session)
|
||||
session.commit()
|
||||
return obj
|
||||
|
||||
def _get(self, context, model, fieldname, value, eager):
|
||||
query = model_query(model)
|
||||
session = get_session()
|
||||
with session.begin():
|
||||
query = model_query(model, session=session)
|
||||
if eager:
|
||||
query = self._set_eager_options(model, query)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user