Merge pull request #2215 from diego-plan9/types_queries

Do not attempt matching unset fields on DateQuery
This commit is contained in:
Diego M. Rodríguez 2016-10-03 20:58:20 +02:00 committed by GitHub
commit 36bc800309
3 changed files with 16 additions and 0 deletions

View file

@ -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)

View file

@ -68,6 +68,8 @@ And there are a few bug fixes too:
a problem that it was not possible to get tokens from the Emby API.
* :doc:`/plugins/lyrics`: Search for lyrics using the title part preceding the
colon character. :bug:`2206`
* Fix a crash when a query contains a date field that is not set for all
the items. :bug:`1938`
The last release, 1.3.19, also erroneously reported its version as "1.3.18"
when you typed ``beet version``. This has been corrected.

View file

@ -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))