Last active
August 29, 2015 14:16
-
-
Save dzimine/dc343f9d48158cc15bde to your computer and use it in GitHub Desktop.
SQL Alchemy: cut parameter on Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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