Skip to content

[FIX] Allow report/template generation outside an HTTP request - #112

Open
Rad0van wants to merge 2 commits into
ONLYOFFICE:feature/19.0from
Data-Dance:fix/requests-outside-http-context
Open

[FIX] Allow report/template generation outside an HTTP request#112
Rad0van wants to merge 2 commits into
ONLYOFFICE:feature/19.0from
Data-Dance:fix/requests-outside-http-context

Conversation

@Rad0van

@Rad0van Rad0van commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Problem

onlyoffice_request() and onlyoffice_urlopen() in onlyoffice_odoo/controllers/controllers.py read request.env directly. request is a werkzeug local proxy that is only bound during an HTTP request, so any code path that triggers ONLYOFFICE report/template generation outside of a web request fails with:

RuntimeError: object is not bound

This happens when generating an ONLYOFFICE-backed report from:

  • the Odoo shell,
  • an ir.cron job,
  • a server action / automated action,
  • mail template rendering driven from any of the above.

A real-world trigger is sending a mail.template whose report attachment is an ONLYOFFICE template, from a scheduled/cron context.

Fix

Add an optional env parameter to both helpers, resolved through a small _resolve_env(env) that falls back to request.env when nothing is passed. Model-layer callers (ir_actions_report and onlyoffice_odoo_templates) now pass env=self.env.

This is fully backward compatible: every existing controller call site (where request is bound) passes nothing and behaves exactly as before.

Changes

  • onlyoffice_odoo: onlyoffice_request/onlyoffice_urlopen accept env=None (falls back to request.env).
  • onlyoffice_odoo_templates: pass env=self.env at the model-layer call sites (report stream fetch, fill_template docbuilder posts, template conversion/create paths).

ruff check passes on all changed files.

🤖 Generated with Claude Code

Rad0van added 2 commits June 30, 2026 18:43
onlyoffice_request/onlyoffice_urlopen read request.env directly, which
raises "object is not bound" when called from the shell, cron or server
actions. Add an optional env parameter (via _resolve_env) that falls
back to request.env, so callers without a bound request can pass their
own environment.
Thread self.env into onlyoffice_request calls in the model layer
(ir_actions_report report stream fetch and fill_template docbuilder
posts, and the template conversion/create paths) so report and
template generation works when invoked outside of an HTTP request
(shell, cron, mail rendering).
@LinneyS
LinneyS requested a review from ZEROM22 July 1, 2026 07:02
@LinneyS LinneyS added the enhancement New feature or request label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants