Eager load KEKDatum record when EncryptedDatum is retrieved

When trying to GET a decrypted secret from Barbican, an exception is
raised. This is due to the KEKDatum record associated with an
EncryptedDatum record attempting to be lazy-loaded after the SQLAlchemy
session is closed. SQLite does not raise an exception, but Postgres does.
Also, the lazy='joined' syntax did not make it obvious that an eager
load was called for, hence this syntax was changed to lazy=False with
a comment added.

Change-Id: I728e2052d8a916da5c1023daf8137774ac04f8f5
Closes-Bug: #1352020
This commit is contained in:
jfwood
2014-08-03 17:27:26 -05:00
parent 81c2440286
commit 6002bd5454

View File

@@ -199,9 +199,10 @@ class ContainerSecret(BASE):
primary_key=True)
name = sa.Column(sa.String(255), nullable=True)
# Eager load this relationship via 'lazy=False'.
container = orm.relationship('Container',
backref=orm.backref('container_secrets',
lazy='joined'))
lazy=False))
secrets = orm.relationship('Secret',
backref=orm.backref('container_secrets'))
@@ -252,7 +253,8 @@ class Secret(BASE, ModelBase):
# building of the list of supported content types when secret
# metadata is retrieved.
# See barbican.api.resources.py::SecretsResource.on_get()
encrypted_data = orm.relationship("EncryptedDatum", lazy='joined')
# Eager load this relationship via 'lazy=False'.
encrypted_data = orm.relationship("EncryptedDatum", lazy=False)
secret_store_metadata = orm.\
relationship("SecretStoreMetadatum",
@@ -342,7 +344,9 @@ class EncryptedDatum(BASE, ModelBase):
cypher_text = sa.Column(sa.Text)
kek_meta_extended = sa.Column(sa.Text)
kek_meta_tenant = orm.relationship("KEKDatum")
# Eager load this relationship via 'lazy=False'.
kek_meta_tenant = orm.relationship("KEKDatum", lazy=False)
def __init__(self, secret=None, kek_datum=None):
"""Creates encrypted datum from a secret and KEK metadata."""