#5505: Self-Referential ForeignKeys broken using newforms form_for_instance
with a
formfield_callback
-------------------------+--------------------------------------------------
Reporter: danlarkin | Owner: nobody
Status: new | Component: django.newforms
Version: SVN | Resolution:
Keywords: | Stage: Unreviewed
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 0
-------------------------+--------------------------------------------------
Comment (by pigletto):
One more important thing is python version you're using.
I've found that under python2.4 copy.deepcopy fails with lambda functions.
Same thing works with python 2.5.
Python2.4:
{{{
Python 2.4.4 (#2, Apr 12 2007, 21:22:23)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> class Tester(object):
... pass
...
>>> a = Tester()
>>> a.func = lambda p: p + 1
>>>
>>> b = copy.deepcopy(a, {})
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.4/copy.py", line 351, in _reconstruct
state = deepcopy(state, memo)
File "/usr/lib/python2.4/copy.py", line 174, in deepcopy
y = copier(x, memo)
File "/usr/lib/python2.4/copy.py", line 268, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.4/copy.py", line 204, in deepcopy
y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.4/copy.py", line 336, in _reconstruct
y = callable(*args)
File "/usr/lib/python2.4/copy_reg.py", line 92, in __newobj__
return cls.__new__(cls, *args)
TypeError: function() takes at least 2 arguments (0 given)
>>>
}}}
Python2.5:
{{{
Python 2.5.1 (r251:54863, May 2 2007, 16:27:44)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> class Tester(object):
... pass
...
>>> a = Tester()
>>> a.func=lambda p: p + 1
>>> b = copy.deepcopy(a, {})
>>> b.func
<function <lambda> at 0x2aedfa332aa0>
>>>
}}}
Maybe there should be a kind of try: except: fallback for using copy
instead of deepcopy?
--
Ticket URL: <http://code.djangoproject.com/ticket/5505#comment:16>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---