Search Fails if Wikipages Aren't Enabled
Description
api.search fails if wikipages are not enabled.
Steps to reproduce
Select a project.id for a project in which wikipages aren't enabled Run api.search(project.id, 'search term')
Versions
Python Version: 3.9.1 python-taiga version: latest (1.0)
Expected behaviour
api.search should return a taiga.client.SearchResult object
Actual behaviour
api.search throws the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.9/site-packages/taiga/client.py", line 100, in search
search_result.wikipages = self.wikipages.parse_list(
KeyError: 'wikipages'
Additional information
If the following fix is acceptable, I'll submit a pull request.
This basically wraps a conditional around line 100 in client.py
if project.is_wiki_activated:
search_result.wikipages = self.wikipages.parse_list(
result['wikipages']
)
else:
search_result.epics = self.epics.parse_list(
result['epics']
)
@uc-cjdavis thanks for spotting this, I think a better solution could be to just wrap it in a try / except
...
try:
search_result.wikipages = self.wikipages.parse_list(result["wikipages"])
exception KeyError:
pass
...
@uc-cjdavis thanks for spotting this, I think a better solution could be to just wrap it in a try / except
... try: search_result.wikipages = self.wikipages.parse_list(result["wikipages"]) exception KeyError: pass ...
@yakky This looks better but would the above allow search to complete successfully (I'm still not up to speed on try/catch syntax)?
@uc-cjdavis yes, in case of an exception it will just skip the line generating the error and it will keep search_result.wikipages empty
@uc-cjdavis yes, in case of an exception it will just skip the line generating the error and it will keep
search_result.wikipagesempty
@yakky Excellent. Once PR #115 is done I'll work on this.
@uc-cjdavis With Taiga 6 I can't reproduce this error: I have updated anyway the SearchResult object with correct attribute name for wikipages and with the count of search results found.