Django Model '<' not supported between instances of 'str' and 'int'

I have a Django script which runs fine locally, but on Render.com it fails with this error:

Sep 4 01:01:54 PM      create_tasks(limit=limit)
Sep 4 01:01:54 PM    File "/opt/render/project/src/scripts/pull_from_outscraper.py", line 94, in create_tasks
Sep 4 01:01:54 PM      for task_object in task_objects[0:limit]:
Sep 4 01:01:54 PM    File "/opt/render/project/src/.venv/lib/python3.9/site-packages/django/db/models/query.py", line 422, in __getitem__
Sep 4 01:01:54 PM      or (k.stop is not None and k.stop < 0)
Sep 4 01:01:54 PM  TypeError: '<' not supported between instances of 'str' and 'int'```

Whatever limit is, it's not an integer but a string, and you'll need an integer for slicing a queryset.

You can (try to) cast it at the time of use –

for task_object in task_objects[:limit]:

should be

for task_object in task_objects[:int(limit)]:
Back to Top