Skip to content

Opening cached record fails in admin #1

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

Closed
nickzam opened this issue May 28, 2009 · 3 comments
Closed

Opening cached record fails in admin #1

nickzam opened this issue May 28, 2009 · 3 comments

Comments

@nickzam
Copy link

nickzam commented May 28, 2009

I experienced some problems in admin site when I tried to use django-caching for my app. ( TypeError: can't pickle instancemethod objects ) when tried to view cached model record.

All works like a charm, but opening cached record in admin site fails :(

Object that caching tried to cache and fails is CachingManyToManyField with values [7L, 11L].

Latest SVN Django 1.1 beta + mysql4.23 + python2.6 + memcache on WinXP sp3 under Django built-in dev server.
See http://paste.pocoo.org/show/119491/

Traceback (most recent call last):
File "d:\python26\Lib\site-packages\django\core\servers\basehttp.py", line 636, in call
return self.application(environ, start_response)
File "D:\Python26\lib\site-packages\django\core\handlers\wsgi.py", line 241, in call
response = self.get_response(request)
File "D:\Python26\Lib\site-packages\django\core\handlers\base.py", line 134, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)
File "D:\Python26\Lib\site-packages\django\core\handlers\base.py", line 154, in handle_uncaught_exception
return debug.technical_500_response(request, _exc_info)
File "D:\Python26\Lib\site-packages\django\core\handlers\base.py", line 92, in get_response
response = callback(request, *callback_args, *_callback_kwargs)
File "d:\python26\Lib\site-packages\django\contrib\admin\sites.py", line 480, in root
return self.model_page(request, _url.split('/', 2))
File "D:\Python26\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, *_kwargs)
File "d:\python26\Lib\site-packages\django\contrib\admin\sites.py", line 499, in model_page
return admin_obj(request, rest_of_url)
File "d:\python26\Lib\site-packages\django\contrib\admin\options.py", line 1094, in call
return self.change_view(request, unquote(url))
File "D:\Python26\lib\site-packages\django\db\transaction.py", line 240, in _commit_on_success
res = func(_args, *_kw)
File "d:\python26\Lib\site-packages\django\contrib\admin\options.py", line 839, in change_view
form = ModelForm(instance=obj)
File "D:\Python26\Lib\site-packages\django\forms\models.py", line 222, in init
object_data = model_to_dict(instance, opts.fields, opts.exclude)
File "D:\Python26\Lib\site-packages\django\forms\models.py", line 140, in model_to_dict
data[f.name] = [obj.pk for obj in f.value_from_object(instance)]
File "d:\python26\Lib\site-packages\django\db\models\fields\related.py", line 940, in value_from_object
return getattr(obj, self.attname).all()
File "D:\Python26\Scripts\gurt\apps\caching\fields.py", line 73, in all
cache.add(key, pk_list, CACHE_DURATION)
File "D:\Python26\Scripts\gurt\apps\caching\cache.py", line 16, in add
return self._cache.add(smart_str(key), value, timeout, min_compress_len)
File "build\bdist.win32\egg\memcache.py", line 443, in add
return self._set("add", key, val, time, min_compress_len)
File "build\bdist.win32\egg\memcache.py", line 681, in _set
store_info = self._val_to_store_info(val, min_compress_len)
File "build\bdist.win32\egg\memcache.py", line 654, in _val_to_store_info
pickler.dump(val)
File "d:\Python26\Lib\copy_reg.py", line 70, in _reduce_ex
raise TypeError, "can't pickle %s objects" % base.name
TypeError: can't pickle instancemethod objects

@mmalone
Copy link
Owner

mmalone commented Jun 3, 2009

Strange. Seems an instance method is being sent to the cache somehow, but that shouldn't happen since the code only caches a list of primary keys. Any info on how I can reproduce it?

@nickzam
Copy link
Author

nickzam commented Jun 3, 2009

I've created a sample quick and dirty error project based on your django-caching here: http://bitbucket.org/zam/django-caching-errorexample/
Go to http://127.0.0.1:8000/admin/ (login: admin, pass:123) and try to add new article. It will fail when you press Save button.
I think that problem was related to my models, but it seems to be related to the django built-in admin contrib. So you can ignore _errormodels.py - it's almost the same as yours (one many2many link to other table).

Here is paste for this error:
http://dpaste.com/50941/

Thank you for support.

@mmalone
Copy link
Owner

mmalone commented Dec 8, 2009

Fixed... thanks to the three forkers who figured this one out (matclayton, anarcher, and baratrion).

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

No branches or pull requests

2 participants