misc: fix |count filter for None values (#53924)
This commit is contained in:
parent
0da7edeab8
commit
de77d99522
|
@ -2565,6 +2565,10 @@ def test_lazy_formdata_count_as_len_filter(pub):
|
||||||
tmpl = Template('{{ form_var_value|count }}')
|
tmpl = Template('{{ form_var_value|count }}')
|
||||||
assert tmpl.render(context) == '4'
|
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):
|
def test_rounding_and_abs_conditions_django(pub, variable_test_data):
|
||||||
for true_condition_value in (
|
for true_condition_value in (
|
||||||
|
|
|
@ -687,6 +687,8 @@ def filter_value(queryset, value):
|
||||||
def count(queryset):
|
def count(queryset):
|
||||||
if hasattr(queryset, 'get_value'):
|
if hasattr(queryset, 'get_value'):
|
||||||
queryset = queryset.get_value() # unlazy
|
queryset = queryset.get_value() # unlazy
|
||||||
|
if queryset is None:
|
||||||
|
return 0
|
||||||
return len(queryset)
|
return len(queryset)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue