Django queryset error when use len(qs) TypeError: argument must be int or float

I dont know what happened with my db but now I can not len my queryset.

I can make a qs with a lot of obj with qs.SignalSma.objects.all() But somehow I can not use len(qs) on that qs or make a loop with that qs

I am getting in this error if I try to do so.

    In [9]: len(qs)
    TypeError                                 Traceback (most recent call last)
    Cell In[9], line 1
    ----> 1 len(qs)
    File ~\OneDrive\Desktop\dev-2023\signal\lib\site-packages\django\db\models\, in QuerySet.__len__(self)
        261 def __len__(self):
    --> 262     self._fetch_all()
        263     return len(self._result_cache)
    File ~\OneDrive\Desktop\dev-2023\signal\lib\site-packages\django\db\models\, in QuerySet._fetch_all(self)
       1322 def _fetch_all(self):
       1323     if self._result_cache is None:
    -> 1324         self._result_cache = list(self._iterable_class(self))
       1325     if self._prefetch_related_lookups and not self._prefetch_done:
       1326         self._prefetch_related_objects()
    File ~\OneDrive\Desktop\dev-2023\signal\lib\site-packages\django\db\models\, in ModelIterable.__iter__(self)
         59 related_populators = get_related_populators(klass_info, select, db)
         60 known_related_objects = [
         61     (field, related_objs, operator.attrgetter(*[
         62         field.attname
         66     ])) for field, related_objs in queryset._known_related_objects.items()
         67 ]
    ---> 68 for row in compiler.results_iter(results):
         69     obj = model_cls.from_db(db, init_list, row[model_fields_start:model_fields_end])
         70     for rel_populator in related_populators:
    File ~\OneDrive\Desktop\dev-2023\signal\lib\site-packages\django\db\models\sql\, in SQLCompiler.apply_converters(self, rows, converters)
       1120     value = row[pos]
       1121     for converter in convs:
    -> 1122         value = converter(value, expression, connection)
       1123     row[pos] = value
       1124 yield row
    File ~\OneDrive\Desktop\dev-2023\signal\lib\site-packages\django\db\backends\sqlite3\, in DatabaseOperations.get_decimalfield_converter.<locals>.converter(value, expression, connection)
        311 def converter(value, expression, connection):
        312     if value is not None:
    --> 313         return create_decimal(value).quantize(quantize_value, context=expression.output_field.context) 
    TypeError: argument must be int or float

Any idea what is happening?? and how can I fix this?

QuerySet objects have it's own counting method. Use it:

qs = SignalSma.objects.all()
qs.count()  # returns number of objects inside the queryset
Back to Top