Create an admin context to refresh template files
Its impractical to pass in the current context to TemplateFiles._refresh, and it will soon be mandatory for all db api context arguments to be not None. This change creates a short-lived context just for the refresh. It will have the same effect as the current behaviour of creating a new session, since the a new session will be associated with the context, so there is no danger of returning stale data from the current session's identity map. This change also makes the context argument mandatory for any raw templates operations that might need one. Change-Id: I156096d736aac4999a3eebe077ed50ef7384ca02
This commit is contained in:
parent
26b0dd2a3e
commit
7a1a65bac2
|
@ -133,7 +133,7 @@ class Template(collections.Mapping):
|
|||
return cls(t.template, template_id=template_id, env=env,
|
||||
files=t_files)
|
||||
|
||||
def store(self, context=None):
|
||||
def store(self, context):
|
||||
"""Store the Template in the database and return its ID."""
|
||||
rt = {
|
||||
'template': self.t,
|
||||
|
|
|
@ -15,6 +15,7 @@ import collections
|
|||
import six
|
||||
import weakref
|
||||
|
||||
from heat.common import context
|
||||
from heat.common.i18n import _
|
||||
from heat.db import api as db_api
|
||||
from heat.objects import raw_template_files
|
||||
|
@ -89,12 +90,13 @@ class TemplateFiles(collections.Mapping):
|
|||
self._refresh()
|
||||
|
||||
def _refresh(self):
|
||||
rtf_obj = db_api.raw_template_files_get(None, self.files_id)
|
||||
ctxt = context.get_admin_context()
|
||||
rtf_obj = db_api.raw_template_files_get(ctxt, self.files_id)
|
||||
_files_dict = ReadOnlyDict(rtf_obj.files)
|
||||
self.files = _files_dict
|
||||
_d[self.files_id] = _files_dict
|
||||
|
||||
def store(self, ctxt=None):
|
||||
def store(self, ctxt):
|
||||
if not self.files or self.files_id is not None:
|
||||
# Do not to persist an empty raw_template_files obj. If we
|
||||
# already have a not null self.files_id, the (immutable)
|
||||
|
|
Loading…
Reference in New Issue