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

The Task "from_dict" constructor should populate "section_id" with None by default using ".get" #93

Open
michael-genson opened this issue Apr 13, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@michael-genson
Copy link

Bug description

Optional fields in the "from_dict" constructor for each object type use .get such that, if the field is missing, it's populated with None. The section_id on class Task does not do this, even though it should default to None.

It seems that the Todoist API always returns a null section_id so this doesn't matter in practice, but if you're mocking the API (for testing) it's a minor inconvenience.

Expected behaviour

If a Task is constructed from a dict that does not have a section_id, it should set section_id to None.

Is reproducible

Yes

To reproduce

# this raises a KeyError due to a missing section_id
task = Task.from_dict(
    {
        "assigner_id": "abc123",
        "assignee_id": "abc123",
        "comment_count": 0,
        "is_completed": False,
        "content": "def234",
        "created_at": "2023-04-24T00:00:00.0000Z",
        "creator_id": "abc123",
        "description": "",
        "labels": [],
        "order": 1,
        "priority": 1,
        "url": "https://github.com/",
    }
)

Steps taken to try to reproduce

N/A, the fix is easy, you can simply replace section_id=obj["section_id"], with section_id=obj.get("section_id") (or, as a user, just supply a null section_id, of course)

Screenshots

N/A

Version information:

  • Package version: v2.0.2
  • Python version: 3.9

Additional information

See https://github.com/Doist/todoist-api-python/blob/main/todoist_api_python/models.py#L158

@michael-genson michael-genson added the bug Something isn't working label Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant