From 41bd6f9a973d86d8c8339dfb9bd305e335e6fa2f Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 20 Jun 2017 16:04:25 -0400 Subject: [PATCH] Explicitly let artpath be missing We really want `Album.artpath` to be None sometimes, and this was relying on some accidental dbcore behavior before. Now, we explicitly mark the field as nullable: it may be a path, or it may be None to indicate that there is no art. --- beets/library.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/beets/library.py b/beets/library.py index 0a64516ad..748f532a5 100644 --- a/beets/library.py +++ b/beets/library.py @@ -144,10 +144,27 @@ class DateType(types.Float): class PathType(types.Type): + """A dbcore type for filesystem paths. These are represented as + `bytes` objects, in keeping with the Unix filesystem abstraction. + """ + sql = u'BLOB' query = PathQuery model_type = bytes + def __init__(self, nullable=False): + """Create a path type object. `nullable` controls whether the + type may be missing, i.e., None. + """ + self.nullable = nullable + + @property + def null(self): + if self.nullable: + return None + else: + return b'' + def format(self, value): return util.displayable_path(value) @@ -873,7 +890,7 @@ class Album(LibModel): _always_dirty = True _fields = { 'id': types.PRIMARY_ID, - 'artpath': PathType(), + 'artpath': PathType(True), 'added': DateType(), 'albumartist': types.STRING,