Opened 9 years ago
Last modified 7 days ago
#28223 assigned Bug
Form not always picklable due to template renderer
| Reported by: | Claude Paroz | Owned by: | Ishan Kumar |
|---|---|---|---|
| Component: | Forms | Version: | 1.11 |
| Severity: | Normal | Keywords: | |
| Cc: | Torsten Bronger, Martin H., Matti Haavikko | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I'm confronted with a random pickling issue with some forms in Django 1.11.
The error is : PicklingError: Can't pickle <type 'function'>: attribute lookup __builtin__.function failed
I tracked the pickling error to the Form.renderer.engine.engine.template_libraries dict.
I can more or less reproduce (different error message, but hopefully same cause) with:
from django.forms.renderers import get_default_renderer import pickle renderer = get_default_renderer() renderer.engine pickle.dumps(renderer) PicklingError: Can't pickle <function add_preserved_filters at 0x7f2468bfc620>: it's not the same object as django.contrib.admin.templatetags.admin_urls.add_preserved_filters
Change History (12)
comment:1 by , 9 years ago
| Summary: | Form not always picklable → Form not always picklable due to template renderer |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:3 by , 8 years ago
comment:4 by , 8 years ago
| Cc: | added |
|---|
To copy over important information from duplicate:
This broke in 1.11 and had worked in 1.10 and before.
comment:5 by , 8 years ago
Is this bug related with this https://docs.djangoproject.com/en/2.1/releases/1.11/#django-template-backends-django-template-render-prohibits-non-dict-context ?
comment:6 by , 8 years ago
I believe template widget rendering (b52c73008a9d67e9ddbb841872dc15cdd3d6ee01 introduced this issue.
comment:7 by , 8 years ago
| Cc: | added |
|---|
comment:8 by , 6 years ago
| Cc: | added |
|---|
comment:9 by , 6 months ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
I'm organizing a contribution event with PyLadies Seoul. I'm taking this ticket for our participants to work on.
Thanks!
follow-up: 11 comment:10 by , 8 days ago
Hi Hwayoung, is anyone from the PyLadies Seoul event still working on this? If not, I’d like to take it. I have a fix that leaves the cached engine out of the renderer’s pickled state (it’s recreated when needed), with regression tests for the DjangoTemplates and Jinja2 renderers and for pickling a rendered form.
comment:11 by , 8 days ago
Replying to Ishan Kumar:
Hi Hwayoung, is anyone from the PyLadies Seoul event still working on this? If not, I’d like to take it. I have a fix that leaves the cached engine out of the renderer’s pickled state (it’s recreated when needed), with regression tests for the DjangoTemplates and Jinja2 renderers and for pickling a rendered form.
Hi Ishan!! feel free to work on this!! Can't wait to see your PR :)
follow-up: 13 comment:12 by , 8 days ago
| Owner: | changed from to |
|---|
comment:13 by , 7 days ago
| Has patch: | set |
|---|
Thanks Hwayoung! The PR is up: https://github.com/django/django/pull/22153
#29411 is a duplicate of this, with a slightly different reproduce case.