diff --git a/docs/changelog.rst b/docs/changelog.rst index 42a8f60b..dea88921 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -64,6 +64,12 @@ v0.15.0 (UNRELEASED) The methods are still not implemented, but now the commands are accepted as valid. +**HTTP frontend** + +- Fix too broad truthness test that caused :class:`~mopidy.models.TlTrack` + objects with ``tlid`` set to ``0`` to be sent to the HTTP client without the + ``tlid`` field. (Fixes: :issue:`501`) + **Extension support** - :class:`~mopidy.config.Secret` is now deserialized to unicode strings instead diff --git a/mopidy/models.py b/mopidy/models.py index fe390ddf..3fc92bb4 100644 --- a/mopidy/models.py +++ b/mopidy/models.py @@ -90,7 +90,7 @@ class ImmutableObject(object): for v in value] elif isinstance(value, ImmutableObject): value = value.serialize() - if value: + if not (isinstance(value, list) and len(value) == 0): data[public_key] = value return data diff --git a/tests/models_test.py b/tests/models_test.py index a0fe08c7..afd1858b 100644 --- a/tests/models_test.py +++ b/tests/models_test.py @@ -95,6 +95,11 @@ class ArtistTest(unittest.TestCase): {'__model__': 'Artist', 'uri': 'uri', 'name': 'name'}, Artist(uri='uri', name='name').serialize()) + def test_serialize_falsy_values(self): + self.assertDictEqual( + {'__model__': 'Artist', 'uri': '', 'name': None}, + Artist(uri='', name=None).serialize()) + def test_to_json_and_back(self): artist1 = Artist(uri='uri', name='name') serialized = json.dumps(artist1, cls=ModelJSONEncoder)