Merge "context: Warn on mixed uses of old and new db methods"

This commit is contained in:
Zuul 2018-12-05 10:38:50 +00:00 committed by Gerrit Code Review
commit 9da2f19f54
1 changed files with 6 additions and 0 deletions

View File

@ -15,6 +15,7 @@
import collections
import copy
import datetime
import warnings
from oslo_context import context as oslo_context
from oslo_db.sqlalchemy import enginefacade
@ -145,6 +146,11 @@ class Context(ContextBaseWithSession):
# TODO(akamyshnikova): checking for session attribute won't be needed
# when reader and writer will be used
if hasattr(super(Context, self), 'session'):
if self._session:
warnings.warn('context.session is used with and without '
'new enginefacade. Please update the code to '
'use new enginefacede consistently.',
DeprecationWarning)
return super(Context, self).session
if self._session is None:
self._session = db_api.get_writer_session()