Skip to content

[18.0][FIX] ai_oca_bridge: avoid crash when request charset is missing#64

Merged
OCA-git-bot merged 1 commit into
OCA:18.0from
SMNDVC:18.0-fix-ai-bridge-callback-charset
May 29, 2026
Merged

[18.0][FIX] ai_oca_bridge: avoid crash when request charset is missing#64
OCA-git-bot merged 1 commit into
OCA:18.0from
SMNDVC:18.0-fix-ai-bridge-callback-charset

Conversation

@SMNDVC
Copy link
Copy Markdown
Contributor

@SMNDVC SMNDVC commented Mar 12, 2026

Problem

The async callback endpoint /ai/response/<execution_id>/<token> decodes the raw request body with request.httprequest.charset.

In some environments, the wrapped request object does not expose a charset attribute, which causes the callback to crash with:

AttributeError: 'Request' object has no attribute 'charset'

As a result, valid async callback payloads return HTTP 500 before _process_response() is reached.

Reproduction

A direct callback request also fails with HTTP 500:

curl -i -X POST "http://localhost:8069/ai/response/138/809e2dac28368ac5491495e6a1e989cbb2595dbff55209bfe211f0ee253b27f8" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{"body":"Record updated successfully."}'
HTTP/1.1 500 INTERNAL SERVER ERROR
Server: Werkzeug/3.0.1 Python/3.12.3
Date: Thu, 12 Mar 2026 12:46:49 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 265
Connection: close

<!doctype html>
<html lang=en>
<title>500 Internal Server Error</title>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.</p>

Fix

Use a safe fallback to UTF-8 when the request object does not provide a charset:

request.httprequest.get_data().decode(
    getattr(request.httprequest, "charset", None) or "utf-8"
)

Result

Async callback payloads such as:

{"body":"Record updated successfully"}

can be processed without crashing when request.httprequest.charset is missing.

Additional context

Possibly fixes issue #54

@etobella
Copy link
Copy Markdown
Member

squash your commits please

@SMNDVC SMNDVC force-pushed the 18.0-fix-ai-bridge-callback-charset branch from 7c9977c to c6d7ec7 Compare May 28, 2026 15:07
@SMNDVC
Copy link
Copy Markdown
Contributor Author

SMNDVC commented May 28, 2026

Hi @etobella, thanks for the review and approval.

I have squashed the branch as requested:

Rebased on the latest OCA/ai 18.0
Combined the fix and pre-commit formatting into a single commit: [18.0][FIX] ai_oca_bridge: avoid crash when request charset is missing
The PR is now 1 commit with the same change.

Thanks again

@OCA-git-bot
Copy link
Copy Markdown
Contributor

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

@etobella
Copy link
Copy Markdown
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Copy Markdown
Contributor

This PR looks fantastic, let's merge it!
Prepared branch 18.0-ocabot-merge-pr-64-by-etobella-bump-patch, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 7571fb2 into OCA:18.0 May 29, 2026
7 checks passed
@OCA-git-bot
Copy link
Copy Markdown
Contributor

Congratulations, your PR was merged at 726323c. Thanks a lot for contributing to OCA. ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants