python-taiga icon indicating copy to clipboard operation
python-taiga copied to clipboard

Search Fails if Wikipages Aren't Enabled

Open uc-cjdavis opened this issue 4 years ago • 4 comments

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 avatar Jul 16 '21 15:07 uc-cjdavis

@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 avatar Oct 23 '21 09:10 yakky

@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 avatar Oct 25 '21 17:10 uc-cjdavis

@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

yakky avatar Oct 25 '21 19:10 yakky

@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

@yakky Excellent. Once PR #115 is done I'll work on this.

uc-cjdavis avatar Oct 27 '21 13:10 uc-cjdavis

@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.

protoroto avatar Aug 22 '23 10:08 protoroto