Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lambda prevents models using this field from pickling #9

Open
jonathanpglick opened this issue Jan 26, 2015 · 1 comment
Open

Lambda prevents models using this field from pickling #9

jonathanpglick opened this issue Jan 26, 2015 · 1 comment

Comments

@jonathanpglick
Copy link

I'm trying to set up object caching for my Django project but the Any Urlfields I'm using are keeping the python serializer from pickling. It seems that this use of a lambda is causing it to throw this error:

 Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Is there a reason that you want to leave this callable?

Could the lambda be removed?

form_field = forms.ModelChoiceField(queryset=model._default_manager.all(), widget=widget)

Or if it needs to be callable, a partial function could work:

from functools import partial

def model_choice_field(model, widget):
    return forms.ModelChoiceField(queryset=model._default_manager.all(), widget=widget)
....
form_field = partial(model_choice_field, model, widget)
@vdboor
Copy link
Member

vdboor commented Apr 30, 2015

This function should indeed be a callable, to avoid hitting the ORM too early. This function could be called from an __init__.py when someone registers a new URL type. If a partial works for you, by all means, provide a nice pull request for it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants