TypeError:instancemethod预计至少有2个参数,得0

时间:2010-09-17 14:16:48

标签: python django

Django 1.1.2& Python 2.6.5

执行看似无辜的查询集时,我不断收到此错误。看起来与http://code.djangoproject.com/ticket/7204中描述的问题完全相同。但是,我正在运行Django 1.1.2,它本应该修复此错误。以前有人处理过类似的事吗?

以下是构造查询的代码:

def get_some_data(self, start_date, end_date):
    qset = Transaction.txn_objects.get_transactions_between(self.business,
                                                            start_date, 
                                                            end_date)
    income_qset = qset.filter(invoiceitem__invoice__customer = self)
    income_qset = income_qset.exclude(
                    account=F("invoiceitem__taxtypes__account_payable"))
    sums = income_qset.aggregate(models.Sum('credit_amount')) # fails here

这是一个删节版本(非常有用):

File ".../models.py" in get_income_between
  200.         sums = income_qset.aggregate(models.Sum('credit_amount'))
File ".../lib/python2.6/site-packages/django/db/models/query.py" in aggregate
  274.         query = self.query.clone()
File ".../lib/python2.6/site-packages/django/db/models/sql/query.py" in clone
  201.         obj.where = deepcopy(self.where, memo=memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  173.                 y = copier(memo)
File ".../lib/python2.6/site-packages/django/utils/tree.py" in __deepcopy__
  61.         obj.children = deepcopy(self.children, memodict)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_list
  228.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  173.                 y = copier(memo)
File ".../lib/python2.6/site-packages/django/utils/tree.py" in __deepcopy__
  61.         obj.children = deepcopy(self.children, memodict)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_list
  228.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  173.                 y = copier(memo)
File ".../lib/python2.6/site-packages/django/utils/tree.py" in __deepcopy__
  61.         obj.children = deepcopy(self.children, memodict)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_list
  228.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  173.                 y = copier(memo)
File ".../lib/python2.6/site-packages/django/utils/tree.py" in __deepcopy__
  61.         obj.children = deepcopy(self.children, memodict)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_list
  228.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_tuple
  235.         y.append(deepcopy(a, memo))
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  338.             state = deepcopy(state, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  162.         y = copier(x, memo)
File "/usr/lib/python2.6/copy.py" in _deepcopy_dict
  255.         y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/usr/lib/python2.6/copy.py" in deepcopy
  189.                 y = _reconstruct(x, rv, 1, memo)
File "/usr/lib/python2.6/copy.py" in _reconstruct
  323.     y = callable(*args)
File "/usr/lib/python2.6/copy_reg.py" in __newobj__
  93.     return cls.__new__(cls, *args)

Exception Type: TypeError at /reports/income_expense/by_customer/32/
Exception Value: instancemethod expected at least 2 arguments, got 0

1 个答案:

答案 0 :(得分:1)

为了使其他人可能遇到此问题,错误是由使用django-multilingual和django.db的F对象组合引起的。重写代码以消除F对象解决了这个问题。

根本原因实际上是Python中的一个错误,有关详细信息,请参阅http://bugs.python.org/issue1515