Fix init method for HasStandardAttributes

Puttting description in the signature of __init__ would make it
consume the first positional argument that was passed in. This
would lead to a difficult to understand traceback from sqlalchemy
when the object was initialized with a positional.

This correctly checks the kwargs for the description and any other
standard attributes rather than leaving it in a positional.

Closes-Bug: #1614897
Change-Id: I264bf5fbfc834d7f5d86a2ad03f5e68a91e2185c
This commit is contained in:
Kevin Benton 2016-08-19 01:34:45 -07:00
parent c96f48162a
commit 43a8d20136
1 changed files with 8 additions and 2 deletions

View File

@ -194,11 +194,17 @@ class HasStandardAttributes(object):
single_parent=True,
uselist=False)
def __init__(self, description='', *args, **kwargs):
def __init__(self, *args, **kwargs):
standard_attr_keys = ['description', 'created_at',
'updated_at', 'revision_number']
standard_attr_kwargs = {}
for key in standard_attr_keys:
if key in kwargs:
standard_attr_kwargs[key] = kwargs.pop(key)
super(HasStandardAttributes, self).__init__(*args, **kwargs)
# here we automatically create the related standard attribute object
self.standard_attr = StandardAttribute(
resource_type=self.__tablename__, description=description)
resource_type=self.__tablename__, **standard_attr_kwargs)
@declarative.declared_attr
def description(cls):