Skip to content

[16.0][FIX] document_page_reference: resolve references with jinja2 3 - #688

Open
parabol123654 wants to merge 1 commit into
OCA:16.0from
parabol123654:16.0-fix-document_page_reference-jinja2-3
Open

parabol123654 wants to merge 1 commit into
OCA:16.0from
parabol123654:16.0-fix-document_page_reference-jinja2-3

Conversation

@parabol123654

Copy link
Copy Markdown

Fixes #687

document_page_reference resolves ${reference} placeholders by overriding Context.resolve. Compiled templates look names up with Context.resolve_or_missing: jinja2 2.x only routes that call to an overridden resolve() in its legacy mode, and jinja2 3.x has no such mode. With jinja2 3.1.2 (the version Odoo 16 requires on Python > 3.10) the override is never called, so the placeholders render as an empty string, silently.

The fix overrides resolve_or_missing instead (as proposed in the issue), which both versions call; ref is still read from self.parent, where Template.render() puts the variables.

Tests: the existing tests cover it (test_check_raw, test_check_reference, test_no_reference). Locally on 16.0 (official odoo:16.0 image, Python 3.9):

  • with Jinja2 3.1.2 + MarkupSafe 2.1.2 on the path, without the fix: these 3 tests fail ('Test Page 1' != '');
  • with the fix: 9/9 green with Jinja2 3.1.2, and 9/9 green with the image's Jinja2 2.11.3.

17.0+ does not use jinja2 in this module.

Assisted-by: Claude Opus 5.5

References are resolved by overriding Context.resolve, but compiled
templates look names up with Context.resolve_or_missing: jinja2 2 only
called an overridden resolve() in a legacy mode, and jinja2 3 (the version
Odoo 16 uses on Python > 3.10) never does. ${reference} placeholders were
then rendered as an empty string, without any error.

Override resolve_or_missing instead, which both versions call.

Fixes OCA#687

Assisted-by: Claude Opus 5.5
@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @etobella,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added mod:document_page_reference Module document_page_reference series:16.0 labels Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:document_page_reference Module document_page_reference series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants