MCPcopy Index your code
hub / github.com/StackStorm/st2 / insert

Method insert

st2common/st2common/persistence/base.py:125–168  ·  view source on GitHub ↗
(
        cls,
        model_object,
        publish=True,
        dispatch_trigger=True,
        log_not_unique_error_as_debug=False,
    )

Source from the content-addressed store, hash-verified

123
124 @classmethod
125 def insert(
126 cls,
127 model_object,
128 publish=True,
129 dispatch_trigger=True,
130 log_not_unique_error_as_debug=False,
131 ):
132 # Late import to avoid very expensive in-direct import (~1 second) when this function
133 # is not called / used
134 from mongoengine import NotUniqueError
135
136 if model_object.id:
137 raise ValueError("id for object %s was unexpected." % model_object)
138 try:
139 model_object = cls._get_impl().insert(model_object)
140 except NotUniqueError as e:
141 if log_not_unique_error_as_debug:
142 LOG.debug("Conflict while trying to save in DB: %s.", six.text_type(e))
143 else:
144 LOG.exception("Conflict while trying to save in DB.")
145 # On a conflict determine the conflicting object and return its id in
146 # the raised exception.
147 conflict_object = cls._get_by_object(model_object)
148 conflict_id = str(conflict_object.id) if conflict_object else None
149 message = six.text_type(e)
150 raise StackStormDBObjectConflictError(
151 message=message, conflict_id=conflict_id, model_object=model_object
152 )
153
154 # Publish internal event on the message bus
155 if publish:
156 try:
157 cls.publish_create(model_object)
158 except:
159 LOG.exception("Publish failed.")
160
161 # Dispatch trigger
162 if dispatch_trigger:
163 try:
164 cls.dispatch_create_trigger(model_object)
165 except:
166 LOG.exception("Trigger dispatch failed.")
167
168 return model_object
169
170 @classmethod
171 def add_or_update(

Callers 9

test_dist_utils.pyFile · 0.45
mock_workflow_recordsMethod · 0.45
mock_task_recordsMethod · 0.45
get_descendantsFunction · 0.45
requestFunction · 0.45
request_task_executionFunction · 0.45

Calls 5

_get_implMethod · 0.45
_get_by_objectMethod · 0.45
publish_createMethod · 0.45

Tested by 2

mock_workflow_recordsMethod · 0.36
mock_task_recordsMethod · 0.36