mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-21 10:29:29 -05:00
Fix: correctly handle dict data with webhook (#9674)
This commit is contained in:
parent
67a97ffc4d
commit
df5af5c8ad
@ -622,19 +622,20 @@ def send_webhook(
|
|||||||
as_json: bool = False,
|
as_json: bool = False,
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
|
post_args = {
|
||||||
|
"url": url,
|
||||||
|
"headers": headers,
|
||||||
|
"files": files,
|
||||||
|
}
|
||||||
if as_json:
|
if as_json:
|
||||||
httpx.post(
|
post_args["json"] = data
|
||||||
url,
|
elif isinstance(data, dict):
|
||||||
json=data,
|
post_args["data"] = data
|
||||||
files=files,
|
|
||||||
headers=headers,
|
|
||||||
).raise_for_status()
|
|
||||||
else:
|
else:
|
||||||
|
post_args["content"] = data
|
||||||
|
|
||||||
httpx.post(
|
httpx.post(
|
||||||
url,
|
**post_args,
|
||||||
content=data,
|
|
||||||
files=files,
|
|
||||||
headers=headers,
|
|
||||||
).raise_for_status()
|
).raise_for_status()
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Webhook sent to {url}",
|
f"Webhook sent to {url}",
|
||||||
@ -645,6 +646,15 @@ def send_webhook(
|
|||||||
)
|
)
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
|
logger.info(
|
||||||
|
f"Webhook sent to {url}",
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(
|
||||||
|
f"Failed attempt sending webhook to {url}: {e}",
|
||||||
|
)
|
||||||
|
raise e
|
||||||
|
|
||||||
|
|
||||||
def run_workflows(
|
def run_workflows(
|
||||||
trigger_type: WorkflowTrigger.WorkflowTriggerType,
|
trigger_type: WorkflowTrigger.WorkflowTriggerType,
|
||||||
|
@ -2614,7 +2614,7 @@ class TestWorkflows(
|
|||||||
)
|
)
|
||||||
|
|
||||||
mock_post.assert_called_once_with(
|
mock_post.assert_called_once_with(
|
||||||
"http://paperless-ngx.com",
|
url="http://paperless-ngx.com",
|
||||||
content="Test message",
|
content="Test message",
|
||||||
headers={},
|
headers={},
|
||||||
files=None,
|
files=None,
|
||||||
@ -2623,6 +2623,20 @@ class TestWorkflows(
|
|||||||
expected_str = "Webhook sent to http://paperless-ngx.com"
|
expected_str = "Webhook sent to http://paperless-ngx.com"
|
||||||
self.assertIn(expected_str, cm.output[0])
|
self.assertIn(expected_str, cm.output[0])
|
||||||
|
|
||||||
|
# with dict
|
||||||
|
send_webhook(
|
||||||
|
url="http://paperless-ngx.com",
|
||||||
|
data={"message": "Test message"},
|
||||||
|
headers={},
|
||||||
|
files=None,
|
||||||
|
)
|
||||||
|
mock_post.assert_called_with(
|
||||||
|
url="http://paperless-ngx.com",
|
||||||
|
data={"message": "Test message"},
|
||||||
|
headers={},
|
||||||
|
files=None,
|
||||||
|
)
|
||||||
|
|
||||||
@mock.patch("httpx.post")
|
@mock.patch("httpx.post")
|
||||||
def test_workflow_webhook_send_webhook_retry(self, mock_http):
|
def test_workflow_webhook_send_webhook_retry(self, mock_http):
|
||||||
mock_http.return_value.raise_for_status = mock.Mock(
|
mock_http.return_value.raise_for_status = mock.Mock(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user