Opened 13 years ago

Closed 13 years ago

#17976 closed Bug (fixed)

Forms BooleanField not picklable

Reported by: Torsten Bronger Owned by: Aymeric Augustin
Component: Forms Version: 1.4
Severity: Release blocker Keywords:
Cc: bronger@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Today, I switched from 1.3 to 1.4 and since then, BooleanFields in forms are not picklable (and thus cacheable) anymore. The following doesn't work since 1.4:

import pickle
from django import forms

class MyForm(forms.Form):
    my_field = forms.BooleanField()

pickle.dump(MyForm(), open("/dev/null", "w"))

Attachments (1)

17976-1.diff (1.8 KB ) - added by Claude Paroz 13 years ago.
Use a module-level function to restore picklability

Download all attachments as: .zip

Change History (7)

comment:1 by Karen Tracey, 13 years ago

Severity: NormalRelease blocker
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Change in behavior was introduced by r17132, with r17131:

>>> from ttt.forms import MyForm
>>> import pickle
>>> pickle.dumps(MyForm())
"ccopy_reg\n_reconstructor\np0\n(cttt.forms\nMyForm\np1\nc__builtin__\nobject\np2\nNtp3\nRp4\n(dp5\nS'files'\np6\n(dp7\nsS'is_bound'\np8\nI00\nsS'error_class'\np9\ncdjango.forms.util\nErrorList\np10\nsS'empty_permitted'\np11\nI00\nsS'fields'\np12\ng0\n(cdjango.utils.datastructures\nSortedDict\np13\nc__builtin__\ndict\np14\n(dp15\nS'my_field'\np16\ng0\n(cdjango.forms.fields\nBooleanField\np17\ng2\nNtp18\nRp19\n(dp20\nS'widget'\np21\ng0\n(cdjango.forms.widgets\nCheckboxInput\np22\ng2\nNtp23\nRp24\n(dp25\nS'is_required'\np26\nI01\nsS'attrs'\np27\n(dp28\nsS'check_test'\np29\nc__builtin__\nbool\np30\nsbsS'initial'\np31\nNsS'creation_counter'\np32\nI28\nsS'required'\np33\nI01\nsS'label'\np34\nNsS'validators'\np35\n(lp36\nsS'help_text'\np37\nV\np38\nsS'localize'\np39\nI00\nsS'error_messages'\np40\n(dp41\ng33\ncdjango.utils.functional\n_lazy_proxy_unpickle\np42\n(cdjango.utils.translation\nugettext\np43\n(VThis field is required.\np44\ntp45\n(dp46\nc__builtin__\nunicode\np47\ntp48\nRp49\nsS'invalid'\np50\ng42\n(g43\n(VEnter a valid value.\np51\ntp52\n(dp53\ng47\ntp54\nRp55\nssS'show_hidden_initial'\np56\nI00\nsbstp57\nRp58\n(dp59\nS'keyOrder'\np60\n(lp61\ng16\nasbsg31\n(dp62\nsS'label_suffix'\np63\nS':'\np64\nsS'prefix'\np65\nNsS'_changed_data'\np66\nNsS'data'\np67\n(dp68\nsS'_errors'\np69\nNsS'auto_id'\np70\nS'id_%s'\np71\nsb."
>>> quit()

With r17132:

>>> from ttt.forms import MyForm
>>> import pickle
>>> pickle.dumps(MyForm())
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\Program Files\Python27\lib\pickle.py", line 1374, in dumps
    Pickler(file, protocol).dump(obj)
  File "c:\Program Files\Python27\lib\pickle.py", line 224, in dump
    self.save(obj)
  File "c:\Program Files\Python27\lib\pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "c:\Program Files\Python27\lib\pickle.py", line 419, in save_reduce
    save(state)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "c:\Program Files\Python27\lib\pickle.py", line 663, in _batch_setitems
    save(v)
  File "c:\Program Files\Python27\lib\pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "c:\Program Files\Python27\lib\pickle.py", line 401, in save_reduce
    save(args)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 562, in save_tuple
    save(element)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "c:\Program Files\Python27\lib\pickle.py", line 663, in _batch_setitems
    save(v)
  File "c:\Program Files\Python27\lib\pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "c:\Program Files\Python27\lib\pickle.py", line 419, in save_reduce
    save(state)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "c:\Program Files\Python27\lib\pickle.py", line 663, in _batch_setitems
    save(v)
  File "c:\Program Files\Python27\lib\pickle.py", line 331, in save
    self.save_reduce(obj=obj, *rv)
  File "c:\Program Files\Python27\lib\pickle.py", line 419, in save_reduce
    save(state)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 649, in save_dict
    self._batch_setitems(obj.iteritems())
  File "c:\Program Files\Python27\lib\pickle.py", line 663, in _batch_setitems
    save(v)
  File "c:\Program Files\Python27\lib\pickle.py", line 286, in save
    f(self, obj) # Call unbound method with explicit self
  File "c:\Program Files\Python27\lib\pickle.py", line 748, in save_global
    (obj, module, name))
PicklingError: Can't pickle <function <lambda> at 0x00000000033DFCF8>: it's not found as django.forms.widgets.<lambda>
>>>

comment:2 by Aymeric Augustin, 13 years ago

Owner: changed from nobody to Aymeric Augustin

comment:3 by Ramiro Morales, 13 years ago

Summary: BooleanField not picklableForms BooleanField not picklable

by Claude Paroz, 13 years ago

Attachment: 17976-1.diff added

Use a module-level function to restore picklability

comment:4 by Claude Paroz, 13 years ago

Has patch: set

comment:5 by Aymeric Augustin, 13 years ago

Triage Stage: AcceptedReady for checkin

Fixed in 9350d1d59c1a4e6a9ac246a808f55da35de0df69.

This must be backported to the 1.4.X branch, but we're in the middle of the migration to GitHub and currently don't have a 1.4 branch. Marking as Ready For Backport.

comment:6 by Aymeric Augustin, 13 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top