rq / django-rq

A simple app that provides django integration for RQ (Redis Queue)
MIT License
1.81k stars 286 forks source link

Admin job detail page error #606

Closed chromium7 closed 1 year ago

chromium7 commented 1 year ago

job detail page sometimes return an error when being opened

error:

ValueError
Need 2 values to unpack in for loop; got 1. 

This probably is the one causing the error, will investigate more on why the error occured https://github.com/rq/django-rq/blob/a800c2448294981c3c10187a9faad6a87f55793e/django_rq/templates/django_rq/job_detail.html#L141-L145

chromium7 commented 1 year ago

Update

This error occurs when one of the kwargs parameter is named items. In this case, when django reads job.kwargs.items in the template, kwargs["items"] is the one being called instead of kwargs.items(), producing an error if kwargs["items"] cant be unpacked.

Reproduce

This issue can be easily replicated, simply pass a dictionary with items as a key into a template context, and iterate the dictionary in the template

# views.py
def ...:
    context = {'kwargs': {'items': 1}}
    return render(request, 'template.html', context)
<!-- template.html -->
{% for key, value in kwargs.items %}
{% endfor %}