misc: fix |count filter for None values (#53924)

This commit is contained in:
Lauréline Guérin 2021-05-11 16:13:15 +02:00
parent 0da7edeab8
commit de77d99522
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 6 additions and 0 deletions

View File

@ -2565,6 +2565,10 @@ def test_lazy_formdata_count_as_len_filter(pub):
tmpl = Template('{{ form_var_value|count }}')
assert tmpl.render(context) == '4'
tmpl = Template('{{ form_var_value|count }}')
assert tmpl.render({}) == '0'
assert tmpl.render({'form_var_value': None}) == '0'
def test_rounding_and_abs_conditions_django(pub, variable_test_data):
for true_condition_value in (

View File

@ -687,6 +687,8 @@ def filter_value(queryset, value):
def count(queryset):
if hasattr(queryset, 'get_value'):
queryset = queryset.get_value() # unlazy
if queryset is None:
return 0
return len(queryset)