Fix dynamic accessor creation on base adapter class

After rebasing on the idiomatic branch it turns out there was an
error on the creation of the dynamic accessors.  This fixes that
issue.
This commit is contained in:
Alex Kavanagh 2016-05-10 10:22:13 +00:00
parent 20d3c49893
commit bce5321154
1 changed files with 7 additions and 1 deletions

View File

@ -37,9 +37,15 @@ class OpenStackRelationAdapter(object):
for field in self.accessors:
meth_name = field.replace('-', '_')
# Get the relation property dynamically
# Note the additional lambda name: is to create a closure over
# meth_name so that a new 'name' gets created for each loop,
# otherwise the same variable meth_name is referenced in each of
# the internal lambdas. i.e. this is (lambda x: ...)(value)
setattr(self.__class__,
meth_name,
property(lambda self: getattr(self.relation, meth_name)))
(lambda name: property(
lambda self: getattr(
self.relation, name)()))(meth_name))
class RabbitMQRelationAdapter(OpenStackRelationAdapter):