Skip to content

Commit

Permalink
Always use specific null values for fixed fields
Browse files Browse the repository at this point in the history
This came out of an attempt to address the mysterious testing problems from
PR #2563 and turned into a big old debacle. As it turns out, the problem came
from calling Item.from_path and getting None for fields that weren't filled
out by the MediaFile data. Everywhere else, we fill out these fixed attributes
with the special null value for the field's type, so it's actually pretty
confusing that these could mysteriously become None. I think it will be saner
all around if we enforce this universally.

There were two possible fixes: one in __getitem__ to check for missing values
and one that set all the missing values in the constructor. I opted for the
former because it has a smaller footprint, but the latter might have slightly
better performance (depending on the ratio of constructions to lookups).
  • Loading branch information
sampsyo committed Jun 20, 2017
1 parent 7e8056b commit b575a1e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion beets/dbcore/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def __getitem__(self, key):
if key in getters: # Computed.
return getters[key](self)
elif key in self._fields: # Fixed.
return self._values_fixed.get(key)
return self._values_fixed.get(key, self._type(key).null)
elif key in self._values_flex: # Flexible.
return self._values_flex[key]
else:
Expand Down

0 comments on commit b575a1e

Please sign in to comment.