Fix an intermittent test failure when creating a template with reply_to

reply_to requires template_type to be already set, but the order
of attribute assignment is not defined when a model object is created
from a dictionary.

This adds a constructor to Template model that makes sure that
template_type is set first when multiple arguments are passed to the
constructor at once.

The problem might still exist when the template is created through the
API, so this is a temporary fix to unblock the release.
This commit is contained in:
Alexey Bezhan
2017-11-22 15:55:11 +00:00
parent 7b1f07dd31
commit e8ce408f6a

View File

@@ -526,6 +526,12 @@ class TemplateProcessTypes(db.Model):
class TemplateBase(db.Model):
__abstract__ = True
def __init__(self, **kwargs):
if 'template_type' in kwargs:
self.template_type = kwargs.pop('template_type')
super().__init__(**kwargs)
id = db.Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
name = db.Column(db.String(255), nullable=False)
template_type = db.Column(template_types, nullable=False)