sqlalchemy / sqlalchemy/mako

Template.render_context(context) (re)sets context['self']

Open
#184 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug low priority runtime
Dominant language
Python
Stars
459
Forks
90
PR merge metrics
No merged PRs in 30d

Description

Migrated issue, originally created by Anonymous

I'm not quite positive that this is a bug, but I’m pretty sure it is.

When Template.render_context() is called, it sets context['self'].
So, if one renders another template like this:

subtemplate.render_context(context)

After the call to render_context(), context['self'] no longer contains the correct namespace. This (at least) causes problems for any <%block>s in the calling template.

I've attached a short test script which demonstrates the problem.


Attachments: test_render_context_bug.py

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the attached test script, imported_issue_attachments/184/test_render_context_bug.py, to reproduce the changed context['self']. Then locate the Template.render_context() entry point, trace how nested rendering affects the caller's context, and use the script's expected behavior as the completion check.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.