Skip to content

Instantly share code, notes, and snippets.

@dzimine
Last active August 29, 2015 14:16
Show Gist options
  • Save dzimine/dc343f9d48158cc15bde to your computer and use it in GitHub Desktop.
Save dzimine/dc343f9d48158cc15bde to your computer and use it in GitHub Desktop.
SQL Alchemy: cut parameter on Update
class WorkflowExecution(mb.MistralSecureModelBase):
"""Contains workflow execution information."""
__tablename__ = 'executions_v2'
id = mb.id_column()
wf_name = sa.Column(sa.String(80))
wf_spec = sa.Column(st.JsonDictType())
start_params = sa.Column(st.JsonDictType())
state = sa.Column(sa.String(20))
state_info = sa.Column(
sa.String(1024),
nullable=True)
input = sa.Column(st.JsonDictType())
output = sa.Column(st.JsonDictType())
context = sa.Column(st.JsonDictType())
# Can't use ForeignKey constraint here because SqlAlchemy will detect
# a circular dependency and raise an error.
parent_task_id = sa.Column(sa.String(36))
# TODO(nmakhotkin): It's not used now, must be fixed later.
trust_id = sa.Column(sa.String(80))
event.listen(
# Catch and trim WorkflowExecution.state_info to always fit allocated size.
WorkflowExecution.state_info,
'set',
lambda t, v, o, i: utils.cut(v, 1020),
retval=True
)
class WorkflowExecution(mb.MistralSecureModelBase):
"""Contains workflow execution information."""
__tablename__ = 'executions_v2'
id = mb.id_column()
wf_name = sa.Column(sa.String(80))
wf_spec = sa.Column(st.JsonDictType())
start_params = sa.Column(st.JsonDictType())
state = sa.Column(sa.String(20))
state_info = sa.Column(
sa.String(1024),
nullable=True,
onupdate=lambda x: utils.cut(x.current_parameters['state_info'], 1))
input = sa.Column(st.JsonDictType())
output = sa.Column(st.JsonDictType())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment