Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bytes concatination error in Client.search() #94

Merged
merged 8 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion discogs_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,17 @@ def search(self, *query, **fields):
(Artists, Releases, Masters, and Labels). The keyword arguments to this
function are serialized into the request's query string.
"""
if type(query) is not tuple:
raise TypeError("{} method is expecting tuple, got {}.".format(
__name__, type(query)
))

Copy link
Contributor Author

@JOJ0 JOJ0 May 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you agree this check is redundant and should be kicked out? As far as I understand *args always passes tuple.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think this can be left out.

if query:
fields['q'] = ' '.join(query)
if type(query) == bytes:
fields['q'] = b' '.join(query)
else:
fields['q'] = ' '.join(query)

return models.MixedPaginatedList(
self,
update_qs(self._base_url + '/database/search', fields),
Expand Down
6 changes: 6 additions & 0 deletions discogs_client/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def test_search(self):
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_bytes_search(self):
results = self.d.search(b'trash80')
self.assertEqual(len(results), 13)
self.assertTrue(isinstance(results[0], Artist))
self.assertTrue(isinstance(results[1], Release))

def test_utf8_search(self):
uni_string = 'caf\xe9'
try:
Expand Down