Opened 7 years ago

Closed 7 years ago

#29411 closed Bug (duplicate)

Pickling of a form fails after a form was used in a template

Reported by: Torsten Bronger Owned by: nobody
Component: Forms Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The following view function fails from its second invocation on:

def main(request):
    import django.forms as forms
    import pickle
    pickle.dump(forms.Form(), open("/dev/null", "wb"))  # This fails, but not at the very first invocation.
    return render(request, "main.html", {"example_form": ExampleForm()})

Steps to reproduce:

  1. django-admin startproject pickle_problem
  2. cd pickle_problem
  3. Apply the attached patch with -p1.
  4. Apply migrations, start testserver.
  5. Open the URL “/” on the testserver. You should see a bogus form with one boolean field.
  6. Reload the page.

What happens:

The pickling of form.Form() fails. See the attached traceback.

I observe this problem since Django 1.11. Up to Django 1.10, it has worked fine for me.

Attachments (2)

testserver_output.log (1.2 KB ) - added by Torsten Bronger 7 years ago.
Output of Django's testserver, including the traceback.
minimal_example.diff (1.6 KB ) - added by Torsten Bronger 7 years ago.
Patch to create a minimal example.

Download all attachments as: .zip

Change History (4)

by Torsten Bronger, 7 years ago

Attachment: testserver_output.log added

Output of Django's testserver, including the traceback.

by Torsten Bronger, 7 years ago

Attachment: minimal_example.diff added

Patch to create a minimal example.

comment:1 by Torsten Bronger, 7 years ago

With the following view function, the error can be reproduced without reloading the page, which may be easier for automatic reproducing:

def main(request):
    pickle.dump(forms.Form(), open("/dev/null", "wb"))
    result = render(request, "main.html", {"example_form": ExampleForm()})
    pickle.dump(forms.Form(), open("/dev/null", "wb"))
    return result

comment:2 by Carlton Gibson, 7 years ago

Resolution: duplicate
Status: newclosed

This looks like a duplicate of #28223. (The traceback error is the same as reported there.)

Note: See TracTickets for help on using tickets.
Back to Top