mirror of
https://github.com/beetbox/beets.git
synced 2025-12-09 18:12:19 +01:00
Do not attempt matching unset fields on DateQuery
Add a comparison at DateQuery.match in order to avoid comparing if the field is not in the item. Revise the existing types_plugin unit tests for explicitely checking the behaviour when the values are unset.
This commit is contained in:
parent
8d7a626074
commit
bc8f422433
2 changed files with 14 additions and 0 deletions
|
|
@ -628,6 +628,8 @@ class DateQuery(FieldQuery):
|
|||
self.interval = DateInterval.from_periods(start, end)
|
||||
|
||||
def match(self, item):
|
||||
if self.field not in item:
|
||||
return False
|
||||
timestamp = float(item[self.field])
|
||||
date = datetime.utcfromtimestamp(timestamp)
|
||||
return self.interval.contains(date)
|
||||
|
|
|
|||
|
|
@ -70,6 +70,10 @@ class TypesPluginTest(unittest.TestCase, TestHelper):
|
|||
self.config['types'] = {'myfloat': u'float'}
|
||||
item = self.add_item(artist=u'aaa')
|
||||
|
||||
# Do not match unset values
|
||||
out = self.list(u'myfloat:10..0')
|
||||
self.assertEqual(u'', out)
|
||||
|
||||
self.modify(u'myfloat=-9.1')
|
||||
item.load()
|
||||
self.assertEqual(item['myfloat'], -9.1)
|
||||
|
|
@ -84,6 +88,10 @@ class TypesPluginTest(unittest.TestCase, TestHelper):
|
|||
false = self.add_item(artist=u'false')
|
||||
self.add_item(artist=u'unset')
|
||||
|
||||
# Do not match unset values
|
||||
out = self.list(u'mybool:true, mybool:false')
|
||||
self.assertEqual(u'', out)
|
||||
|
||||
# Set true
|
||||
self.modify(u'mybool=1', u'artist:true')
|
||||
true.load()
|
||||
|
|
@ -112,6 +120,10 @@ class TypesPluginTest(unittest.TestCase, TestHelper):
|
|||
old = self.add_item(artist=u'prince')
|
||||
new = self.add_item(artist=u'britney')
|
||||
|
||||
# Do not match unset values
|
||||
out = self.list(u'mydate:..2000')
|
||||
self.assertEqual(u'', out)
|
||||
|
||||
self.modify(u'mydate=1999-01-01', u'artist:prince')
|
||||
old.load()
|
||||
self.assertEqual(old['mydate'], mktime(1999, 1, 1))
|
||||
|
|
|
|||
Loading…
Reference in a new issue