Commit d29d1909 authored by Quentin Defenouillere's avatar Quentin Defenouillere Committed by Vincent A

weboob.browser.filters: Handle values with empty() for numeric values


amount = Coalesce(
    CleanDecimal.US('//xpath', default=NotAbailable),
    CleanDecimal.US('//xpath2', default=NotAvailable),

If one of the CleanDecimal returns NotAvailable and the other '0.00', with
the current behavior, Coalesce will crash with "All falsy and no default"
because we use "if value" in the loop of the filter.

With empty(value), Coalesce accepts 0.00 as a valid value for numeric
parent c7b6e6d9
......@@ -26,6 +26,7 @@ import unidecode
from collections import Iterator
from decimal import Decimal, InvalidOperation
from itertools import islice
from numbers import Number
from dateutil.parser import parse as parse_date
from import gettz
......@@ -1017,7 +1018,8 @@ class Coalesce(MultiFilter):
def filter(self, values):
for value in values:
if value:
# Accept '0.00' as valid value for numeric elements
if value or (isinstance(value, Number) and not empty(value)):
return value
return self.default_or_raise(FilterError('All falsy and no default.'))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment