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.
This commit is contained in:
Adrian Sampson 2017-06-20 16:04:25 -04:00
parent 2a9be17cf6
commit 41bd6f9a97

View file

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