My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 47: Overwriting the save-method
3 people starred this issue and may be notified of changes. Back to list
Status:  Fixed
Owner:  ----
Closed:  Sep 2010


 
Reported by fcat1...@googlemail.com, Feb 26, 2009
I need to overwrite the save-method of a model which uses mptt. Everytime I
try to save I get an Integrity-Error becuase lft is null. So I used
insert_node(node, target, position='last-child', commit=False):

ModelA(models.Model):
    ....
    
    save():
       # doing some stuff

       ModelA.tree.insert_node(self, self.parent)
       super(ModelA, self).save()


=> The result is an AttributeError:
'Options' object has no attribute 'parent_attr' in
Python24\lib\site-packages\mptt\models.py in is_root_node line 179


May 14, 2010
#1 Saturday...@gmail.com
I'm also having problems overriding a the save() method of a model that's using mptt.
 The error I'm getting is the following:

    ValueError at /admin/myapp/mymodeladd/
    Cannot use None as a query value

Here's the traceback:

Environment:

Request Method: POST
Request URL: http://localhost:8000/admin/scrivener/page/add/
Django Version: 1.2 rc 1 SVN-13117
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.sitemaps',
 'mptt',
 'filebrowser',
 'south',
 'haystack',
 'django_static',
 'etc',
 'scrivener',
 'gregor',
 'annunciator']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "B:\django-apps\3rd Party Source\django\core\handlers\base.py" in get_response
  100.                     response = callback(request, *callback_args,
**callback_kwargs)
File "B:\django-apps\3rd Party Source\django\contrib\admin\options.py" in wrapper
  239.                 return self.admin_site.admin_view(view)(*args, **kwargs)
File "B:\django-apps\3rd Party Source\django\utils\decorators.py" in _wrapped_view
  74.                     response = view_func(request, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\views\decorators\cache.py" in
_wrapped_view_func
  69.         response = view_func(request, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\contrib\admin\sites.py" in inner
  190.             return view(request, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\utils\decorators.py" in _wrapper
  21.             return decorator(bound_func)(*args, **kwargs)
File "B:\django-apps\3rd Party Source\django\utils\decorators.py" in _wrapped_view
  74.                     response = view_func(request, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\utils\decorators.py" in bound_func
  17.                 return func(self, *args2, **kwargs2)
File "B:\django-apps\3rd Party Source\django\db\transaction.py" in _commit_on_success
  299.                     res = func(*args, **kw)
File "B:\django-apps\3rd Party Source\django\contrib\admin\options.py" in add_view
  795.                 self.save_model(request, new_object, form, change=False)
File "B:\django-apps\3rd Party Source\django\contrib\admin\options.py" in save_model
  597.         obj.save()
File "B:\django-apps\scrivener\models.py" in save
  211. 		self.url = self.get_absolute_url()
File "B:\django-apps\3rd Party Source\django\utils\functional.py" in _curried
  55.         return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "B:\django-apps\3rd Party Source\django\db\models\base.py" in get_absolute_url
  940.     return settings.ABSOLUTE_URL_OVERRIDES.get('%s.%s' % (opts.app_label,
opts.module_name), func)(self, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\db\models\__init__.py" in inner
  31.         bits = func(*args, **kwargs)
File "B:\django-apps\scrivener\models.py" in get_absolute_url
  194. 		for ancestor in self.get_ancestors():
File "B:\django-apps\3rd Party Source\mptt\models.py" in get_ancestors
  23.         opts.tree_id_attr: getattr(self, opts.tree_id_attr),
File "B:\django-apps\3rd Party Source\django\db\models\manager.py" in filter
  141.         return self.get_query_set().filter(*args, **kwargs)
File "B:\django-apps\3rd Party Source\django\db\models\query.py" in filter
  550.         return self._filter_or_exclude(False, *args, **kwargs)
File "B:\django-apps\3rd Party Source\django\db\models\query.py" in _filter_or_exclude
  568.             clone.query.add_q(Q(*args, **kwargs))
File "B:\django-apps\3rd Party Source\django\db\models\sql\query.py" in add_q
  1131.                             can_reuse=used_aliases)
File "B:\django-apps\3rd Party Source\django\db\models\sql\query.py" in add_filter
  1000.                 raise ValueError("Cannot use None as a query value")

Exception Type: ValueError at /admin/scrivener/page/add/
Exception Value: Cannot use None as a query value

Sep 3, 2010
#2 matjaz.c...@gmail.com
If I'm not mistaken, the original bug reporter had some issues with understanding how django-mptt works, but the second comment is a genuine error, could you test the new release and test if this happens with latest stable release?
Status: Chatting
Sep 20, 2010
Project Member #3 craig.ds@gmail.com
Presumedly the tell-tale bits of that traceback are:

File "B:\django-apps\scrivener\models.py" in save
  211. 		self.url = self.get_absolute_url()

...

File "B:\django-apps\scrivener\models.py" in get_absolute_url
  194. 		for ancestor in self.get_ancestors():


So it looks like self.get_ancestors() is failing on new nodes that haven't been saved yet?

I tested this in latest master (django 1.1, python 2.6.5, ubuntu 10.04), looks like it's working as expected now.

If anyone's still having this problem with the latest source checkout, please comment and we'll reopen
Status: Fixed

Powered by Google Project Hosting