@classmethod error: TypeError: __call __ () принимает 2 позиционных аргумента, но 3 были заданы - PullRequest
0 голосов
/ 16 октября 2018

У меня есть модель / класс, подобный этому:

class MyModel(TimeStampedModel):
    some_field = models.CharField()

    @classmethod
    def my_class_method(cls, value, other_value):
        print(value)

Однако, когда я делаю это из другого вида:

value = "Test"
MyModel.my_class_method(value, other_value)

Я получаю ошибку: TypeError: __call__() takes 2 positional arguments but 3 were given

Мне кажется, что я схожу с ума.

Модель, для которой я делаю это, имеет:

class Meta:
    abstract = True

Редактировать: Полный возврат (используя мои настоящие имена функций):

Traceback (most recent call last):
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\whitenoise\base.py", line 66, in __call__
    return self.application(environ, start_response)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\wsgi.py", line 146, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 81, in get_response
    response = self._middleware_chain(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\whitenoise\middleware.py", line 25, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\utils\deprecation.py", line 95, in __call__
    response = self.get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 37, in inner
    response = response_for_exception(request, exc)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 87, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 122, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Users\Cole\PycharmProjects\webapp\config\wsgi.py", line 27, in null_technical_500_response
    six.reraise(exc_type, exc_value, tb)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\exception.py", line 35, in inner
    response = get_response(request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Cole\AppData\Local\Programs\Python\Python36-32\lib\site-packages\django\contrib\auth\decorators.py", line 21, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "C:\Users\Cole\PycharmProjects\webapp\vendor_app\apps\users\decorators.py", line 14, in wrap
    return function(request, *args, **kwargs)
  File "C:\Users\Cole\PycharmProjects\webapp\vendor_app\apps\core\locations\views.py", line 56, in location_detail_view
    Location.create_or_update_location(form, formset)
TypeError: __call__() takes 2 positional arguments but 3 were given

1 Ответ

0 голосов
/ 25 октября 2018

Похоже, что проблема была вызвана переносом метода класса также в атомарный декоратор транзакции:

@transaction.atomic
@classmethod
def my_function(cls, **kwargs):
    ... my function

Видимо, это не работает.

...