From 7d3bb6862eb3f8e9dc0ee62be27845c9920a05a6 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 27 Nov 2018 23:24:27 +0900 Subject: [PATCH] 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 --- neutron_lib/context.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/neutron_lib/context.py b/neutron_lib/context.py index 750f9b572..f323222ea 100644 --- a/neutron_lib/context.py +++ b/neutron_lib/context.py @@ -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()