Skip to content
This repository was archived by the owner on Feb 21, 2022. It is now read-only.
This repository was archived by the owner on Feb 21, 2022. It is now read-only.

'str' object has no attribute 'get' in labels.py #83

@rosenpin

Description

@rosenpin

Hi, I'm trying to use the API and it seems that in some circumstances I get this error when trying to get a label:

File "/home/ubuntu/.local/lib/python3.8/site-packages/todoist/managers/labels.py", line 72, in get
    if obj.get("label"):
AttributeError: 'str' object has no attribute 'get'

The code part in question is the following:

    def get(self, label_id):
        """
        Gets an existing label.
        """
        params = {"token": self.token, "label_id": label_id}
        obj = self.api._get("labels/get", params=params)
        if obj and "error" in obj:
            return None
        data = {"labels": []}
        if obj.get("label"):
            data["labels"].append(obj.get("label"))
        self.api._update_state(data)
        return obj

The problematic line is this:

        if obj.get("label"):

Seems like in some situations the obj returned from self.api._get is a string object?
Kind of weird, anyway this causes an exception and obviously doesn't return the label

Update:

Seems like it only happens when I'm trying to access labels concurrently

Update 2:

Managed to solve it for my case for now by avoiding concurrently accessing labels, I didn't check if it happens when trying to access the same label or 2 labels in parallel in general.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions