Skip to content

Can't get project by slug as Projects instance parse fails #188

Closed
@XaverStiensmeier

Description

@XaverStiensmeier

Description

Executing:

from taiga import TaigaAPI
api = TaigaAPI()
api.auth(username=USERNAME, password=PASSWORD)
project = api.projects.get_by_slug(PROJECT_SLUG)

I get:

Traceback (most recent call last):
  File "/home/xaver/Documents/Repos/taigaRESTInteraction/create_usertickets.py", line 22, in <module>
    project = api.projects.get_by_slug(PROJECT_SLUG)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xaver/Documents/Repos/taigaRESTInteraction/venv/lib/python3.12/site-packages/taiga/models/models.py", line 1803, in get_by_slug
    return self.instance.parse(self.requester, response.json())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xaver/Documents/Repos/taigaRESTInteraction/venv/lib/python3.12/site-packages/taiga/models/base.py", line 199, in parse
    entry[key_to_parse] = cls_to_parse.parse(requester, entry[key_to_parse])
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xaver/Documents/Repos/taigaRESTInteraction/venv/lib/python3.12/site-packages/taiga/models/base.py", line 107, in parse
    for entry in entries:
TypeError: 'NoneType' object is not iterable

It's not like entries = [None] or something, but more that the parsers gets (last lines before error) see below. Logging format print("Entry {line of code in base.py where the print is placed}", entry):

Entry 106: [{'id': 9688125, 'name': 'Wartend', 'order': 1, 'is_closed': False, 'project_id': 1599549, 'color': '#70728F', 'wip_limit': None, 'slug': 'wartend', 'is_archived': False}, {'id': 9688126, 'name': 'In Bearbeitung', 'order': 2, 'is_closed': False, 'project_id': 1599549, 'color': '#51CFD3', 'wip_limit': None, 'slug': 'in-bearbeitung', 'is_archived': False}, {'id': 9688127, 'name': 'In Verzug', 'order': 3, 'is_closed': False, 'project_id': 1599549, 'color': '#E44057', 'wip_limit': None, 'slug': 'in-verzug', 'is_archived': False}, {'id': 9688129, 'name': 'Done', 'order': 5, 'is_closed': True, 'project_id': 1599549, 'color': '#A8E440', 'wip_limit': None, 'slug': 'done', 'is_archived': False}, {'id': 9688130, 'name': 'Archived', 'order': 6, 'is_closed': True, 'project_id': 1599549, 'color': '#A9AABC', 'wip_limit': None, 'slug': 'archived', 'is_archived': True}]
Entry 196 {'id': 9688125, 'name': 'Wartend', 'order': 1, 'is_closed': False, 'project_id': 1599549, 'color': '#70728F', 'wip_limit': None, 'slug': 'wartend', 'is_archived': False}
Entry 196 {'id': 9688126, 'name': 'In Bearbeitung', 'order': 2, 'is_closed': False, 'project_id': 1599549, 'color': '#51CFD3', 'wip_limit': None, 'slug': 'in-bearbeitung', 'is_archived': False}
Entry 196 {'id': 9688127, 'name': 'In Verzug', 'order': 3, 'is_closed': False, 'project_id': 1599549, 'color': '#E44057', 'wip_limit': None, 'slug': 'in-verzug', 'is_archived': False}
Entry 196 {'id': 9688129, 'name': 'Done', 'order': 5, 'is_closed': True, 'project_id': 1599549, 'color': '#A8E440', 'wip_limit': None, 'slug': 'done', 'is_archived': False}
Entry 196 {'id': 9688130, 'name': 'Archived', 'order': 6, 'is_closed': True, 'project_id': 1599549, 'color': '#A9AABC', 'wip_limit': None, 'slug': 'archived', 'is_archived': True}
Entry 106: []
Entry 106: None

Steps to reproduce

from taiga import TaigaAPI
api = TaigaAPI()
api.auth(username=USERNAME, password=PASSWORD)
project = api.projects.get_by_slug(PROJECT_SLUG)

Versions

  • Python 3.12.3
  • I don't think I have django installed at least I can't import it python -c "import django; print(django.get_version())"
  • What application version do you mean? I installed python taiga via the pip command on Ubuntu24.04

Expected behaviour

Get the project - while I get a correct JSON response, the error occurs while interpreting it.

Actual behaviour

I get an error saying that entries can't be iterated.

Additional information

The JSON response looks correct. It is just the interpreting that throws the error. I will try to debug this further on my machine.

Fix?

I have just changed the ListResource method to:

@classmethod
    def parse(cls, requester, entries):
        """Parse a JSON array into a list of model instances."""
        print("Entry 106:", entries)
        result_entries = SearchableList()
        for entry in entries or []: # changed to handle the None case
               result_entries.append(cls.instance.parse(requester, entry))
        return result_entries

not sure if that's a good way to handle it, but it seems to work for my needs for now.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions