如何删除或更新具有TypeError的对象?

时间:2019-06-15 16:15:32

标签: python django python-3.x typeerror

我的应用程序创建了一个带有错误的对象,用户插入了一个字符串(我相信),但该字段为Decimal。

我知道表单会阻止它,但是插入发生在post_save装饰器上,现在我无法访问该对象,对其进行更新或删除。

comandas_antecipadas = ComandaAntecipado.objects.all()
comandas_antecipadas
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 244, in __repr__
    data = list(self[:REPR_OUTPUT_SIZE + 1])
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 268, in __iter__
    self._fetch_all()
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 63, in __iter__
    for row in compiler.results_iter(results):
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1009, in apply_converters
    value = converter(value, expression, connection)
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\backends\sqlite3\operations.py", line 254, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
TypeError: argument must be int or float

comandas_antecipadas.count()
11
comandas_antecipadas[9]
<ComandaAntecipado: ComandaAntecipado object (120)>
comandas_antecipadas[10]
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 302, in __getitem__
    qs._fetch_all()
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 1186, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\query.py", line 63, in __iter__
    for row in compiler.results_iter(results):
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\models\sql\compiler.py", line 1009, in apply_converters
    value = converter(value, expression, connection)
  File "C:\projetos\barzim\venv\lib\site-packages\django\db\backends\sqlite3\operations.py", line 254, in converter
    return create_decimal(value).quantize(quantize_value, context=expression.output_field.context)
TypeError: argument must be int or float

1 个答案:

答案 0 :(得分:0)

当您尝试在控制台中显示对象时,您的问题正在发生。所以,不要那样做。只需直接将其删除:

comandas_antecipadas = ComandaAntecipado.objects.all()
comandas_antecipadas[9].delete()