workflow: record a LoggedError on wscall status error (#48946)
This commit is contained in:
parent
61e485e6ba
commit
0dd771dae6
|
@ -12,6 +12,7 @@ import pytest
|
|||
from webtest import Upload
|
||||
|
||||
from wcs.qommon.http_request import HTTPRequest
|
||||
from wcs.logged_errors import LoggedError
|
||||
from wcs.roles import Role
|
||||
from wcs.workflows import (
|
||||
Workflow, WorkflowCriticalityLevel, DisplayMessageWorkflowStatusItem,
|
||||
|
@ -1749,6 +1750,41 @@ def test_workflows_wscall_options(pub, value):
|
|||
assert resp.form['record_on_errors'].value == ('yes' if not value else None)
|
||||
|
||||
|
||||
def test_workflows_wscall_status_error(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
LoggedError.wipe()
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
baz_status = workflow.add_status(name='baz')
|
||||
foo_status = workflow.add_status(name='foo')
|
||||
wscall = WebserviceCallStatusItem()
|
||||
wscall.parent = baz_status
|
||||
wscall.action_on_app_error = foo_status.id
|
||||
wscall.action_on_4xx = foo_status.id
|
||||
wscall.action_on_5xx = foo_status.id
|
||||
wscall.action_on_bad_data = foo_status.id
|
||||
wscall.action_on_network_errors = foo_status.id
|
||||
baz_status.items.append(wscall)
|
||||
workflow.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
assert LoggedError.count() == 0
|
||||
|
||||
# delete foo status
|
||||
del workflow.possible_status[1]
|
||||
workflow.store()
|
||||
app.get('/backoffice/workflows/%s/' % workflow.id)
|
||||
assert LoggedError.count() == 1
|
||||
error = LoggedError.select()[0]
|
||||
assert error.tech_id == '%s-reference-to-invalid-status-in-workflow-foo-status-baz-item-webservice' % workflow.id
|
||||
assert error.formdef_id is None
|
||||
assert error.workflow_id == workflow.id
|
||||
assert error.summary == 'reference to invalid status in workflow foo, status baz, item Webservice'
|
||||
assert error.occurences_count == 5
|
||||
|
||||
|
||||
def test_workflows_inspect_view(pub):
|
||||
from wcs.workflows import WorkflowVariablesFieldsFormDef
|
||||
from wcs.wf.form import FormWorkflowStatusItem, WorkflowFormFieldsFormDef
|
||||
|
|
|
@ -80,15 +80,14 @@ class LoggedError(XmlStorableObject):
|
|||
error.formdef_id = formdef.id
|
||||
error.workflow_id = formdef.workflow.id
|
||||
error.formdef_class = formdef.__class__.__name__
|
||||
elif workflow:
|
||||
error.workflow_id = workflow.id
|
||||
|
||||
if not error.formdef_id:
|
||||
# cannot attach error to formdef, don't record in journal, it will
|
||||
if not error.formdef_id and not error.workflow_id:
|
||||
# cannot attach error to formdef or workflow, don't record in journal, it will
|
||||
# still be sent by email to administrators.
|
||||
return
|
||||
|
||||
if not error.workflow_id:
|
||||
error.workflow_id = workflow.id
|
||||
|
||||
if status_item:
|
||||
error.status_item_id = status_item.id
|
||||
if getattr(status_item, 'parent', None):
|
||||
|
@ -131,7 +130,10 @@ class LoggedError(XmlStorableObject):
|
|||
|
||||
@property
|
||||
def tech_id(self):
|
||||
tech_id = '%s-%s-' % (self.formdef_id, self.workflow_id)
|
||||
tech_id = ''
|
||||
if self.formdef_id:
|
||||
tech_id += '%s-' % self.formdef_id
|
||||
tech_id += '%s-' % self.workflow_id
|
||||
if self.status_id:
|
||||
tech_id += '%s-' % self.status_id
|
||||
if self.status_item_id:
|
||||
|
|
|
@ -447,11 +447,13 @@ class WebserviceCallStatusItem(WorkflowStatusItem):
|
|||
try:
|
||||
target = self.parent.parent.get_status(value)
|
||||
except KeyError:
|
||||
get_publisher().get_app_logger().error(
|
||||
'reference to invalid status in workflow %r, status %r, item %r' % (
|
||||
self.parent.parent.name,
|
||||
self.parent.name,
|
||||
self.description))
|
||||
from wcs.logged_errors import LoggedError
|
||||
message = _('reference to invalid status in workflow %(workflow)s, status %(status)s, item %(item)s') % {
|
||||
'workflow': self.parent.parent.name,
|
||||
'status': self.parent.name,
|
||||
'item': self.description,
|
||||
}
|
||||
LoggedError.record(message, workflow=self.parent.parent)
|
||||
continue
|
||||
targets.append(target)
|
||||
return targets
|
||||
|
|
Loading…
Reference in New Issue