From 585d4ba89d19da669def0cef38a94065158fd2b7 Mon Sep 17 00:00:00 2001 From: Barry Broderick Date: Mon, 20 Nov 2017 09:56:40 -0500 Subject: [PATCH 1/4] attempted fix for #2740 --- beetsplug/hook.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/beetsplug/hook.py b/beetsplug/hook.py index 833f0feaa9..dac38be445 100644 --- a/beetsplug/hook.py +++ b/beetsplug/hook.py @@ -68,6 +68,8 @@ def convert_field(self, value, conversion): converted = converted.decode(self._coding) except UnicodeEncodeError: pass + except AttributeError: + converted = value return converted From a7818027ab83d98ba7a613d74c40455797c235c6 Mon Sep 17 00:00:00 2001 From: Barry Broderick Date: Mon, 20 Nov 2017 23:08:59 -0500 Subject: [PATCH 2/4] replaced the exception test in convert_field with an isinstance test --- beetsplug/hook.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/beetsplug/hook.py b/beetsplug/hook.py index dac38be445..4f33906a42 100644 --- a/beetsplug/hook.py +++ b/beetsplug/hook.py @@ -64,13 +64,9 @@ def convert_field(self, value, conversion): converted = super(CodingFormatter, self).convert_field(value, conversion) - try: - converted = converted.decode(self._coding) - except UnicodeEncodeError: - pass - except AttributeError: - converted = value - + if isinstance(converted, bytes): + return converted.decode(self._coding) + return converted From 530beb6312795367a126b7bf15a03c38108b87b6 Mon Sep 17 00:00:00 2001 From: Barry Broderick Date: Wed, 22 Nov 2017 10:10:28 -0500 Subject: [PATCH 3/4] removed whitespaces from empty line --- beetsplug/hook.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beetsplug/hook.py b/beetsplug/hook.py index 4f33906a42..b6270fd500 100644 --- a/beetsplug/hook.py +++ b/beetsplug/hook.py @@ -66,7 +66,7 @@ def convert_field(self, value, conversion): if isinstance(converted, bytes): return converted.decode(self._coding) - + return converted From 481378638242cf3137abadb097803de49fa86bcc Mon Sep 17 00:00:00 2001 From: Barry Broderick Date: Wed, 22 Nov 2017 10:21:00 -0500 Subject: [PATCH 4/4] updated changelog to include fix for #2740 --- docs/changelog.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index d20bc86f6c..fe19403f09 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -34,6 +34,10 @@ New features: Fixes: +* :doc:`/plugins/hook`: Fixed a problem whereby accessing non-string properties of + objects such as item or album (e.g. item.track) would cause a crash. + Thanks to :user:`broddo`. + :bug:`2740` * :doc:`/plugins/play`: When ``relative_to`` is set, correctly emit relative paths even when querying for albums rather than tracks. Thanks to :user:`j000`.