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

It ends up with two sessions for a context and can lead
subtle caching issues.

Related-Bug: #1803745
Change-Id: Ic04efbe6915293d2f8d181c9a5348cc8aa58bd62
This commit is contained in:
YAMAMOTO Takashi 2018-11-27 23:24:27 +09:00
parent 53bc87c198
commit 7d3bb6862e
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()