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

api.state['day_orders'] broken? #90

Open
silentjay opened this issue Nov 28, 2020 · 6 comments
Open

api.state['day_orders'] broken? #90

silentjay opened this issue Nov 28, 2020 · 6 comments

Comments

@silentjay
Copy link

My understanding from the docs is that item.day_order returns an integer of where a task sits in the queue in relation to other tasks in the Today view. However in my case where i'm using a custom sort for the web apps Today view the tasks day_order always return -1. I've tried changing the sort type in the web app but still I get -1 returned for all my tasks.

Am I missing a big piece of the puzzle here? Am I misunderstanding the true nature of day_order?

@6uhrmittag
Copy link

I just found it in the docs! The day_order is stored separately from the item itself: https://developer.todoist.com/sync/v8/#read-resources (see Response).

To list:

    print(api.state['day_orders'])

That also explains why the reordering must be done separately as well:

>>> api.items.update_day_orders({33548400: 1})

(Source: docs)

@silentjay
Copy link
Author

silentjay commented Dec 6, 2020

Good find @6uhrmittag, it sounds like according to the docs this is what I would need A JSON object specifying the order of items in daily agenda. However in my case api.state['day_orders'] returns 257 items, while the actual tasks due today are 52. Even more interesting is that none of my tasks due today ids are present in those 257 items.

Taking this further api.state['items'] returns 255 items. So I ran a test and not a single ID of these tasks matches any of the IDs of the tasks returned in api.state['day_orders']. You would think these two lists would have identical task IDs.

Have you tested this yourself? Does it work as you would expect? I'm either missing an important way of how day_orders works or this part of the API is completely broken.

@6uhrmittag
Copy link

Have you tested this yourself? Does it work as you would expect?

Viewing the order, yes:

    print(api.items.get_by_id(4281365212)['content'])
    print(api.items.get_by_id(4945505327)['content'])
    print('state[item]: date_order: ' + str(api.items.get_by_id(4281365212)['day_order']))
    print('state[item]: date_order: ' + str(api.items.get_by_id(4945505327)['day_order']))
    orders = api.state['day_orders']
    print(orders)
    print('state[day_orders]: date_order: ' + str(orders['4281365212']))
    print('state[day_orders]: date_order: ' + str(orders['4945505327']))
    exit(1)

After reordering the tasks in the web app, the numbers change.

But! The the ordering-function itself is somewhat broken, which makes the ordering values unpredictable (for me).
After some digging, I even found it in the manual:

Can I manually reorder tasks in the list view when sorting is active?
No. Once you’ve set a sorting option for your tasks, you will not be able to manually reorder them.

(Source: https://get.todoist.help/hc/en-us/articles/360017135159-How-to-sort-your-tasks)

It has also been mentioned multiple times in reddit.com/r/todoist.
It's a rather new feature and it's probably includes a weird logic in the clients...

api.state['day_orders'] returns 257 items, while the actual tasks due today are 52

I think this is because there can be overdue items in the today view as well. Again, probably a weird logic in the clients...

... so, I guess viewing the values works. But working with it isn't intuitive right now.

@silentjay
Copy link
Author

silentjay commented Dec 6, 2020

We're having two separate issues. I can't even get the results of api.state['day_orders'] to make any sense. I've compared all the ids to api.state['items'] and I can only match 10 tasks. Most of which don't even have due dates. What the other 247 task IDs in days_orders relate to I have no idea. The fact that day_orders returns more items than items is another indicator that maybe it's not just me not understanding how the api works but that its' broken, at least for me as these two lists are not in sync.

        print(f'api.state["items"]: {len(api.state["items"])}')
        print(f'api.state["day_orders"]: {len(api.state["day_orders"])}')
        for day_order_id, value in api.state['day_orders'].items():
            for task in api.state['items']:
                if int(task['id']) == int(day_order_id):
                    print(task['content'])

@6uhrmittag
Copy link

but that its' broken

I think so. Or not fully finished. The sorting is relatively new and the last commit to this repo is 3 month old...

I just want to add one last observation I've made:

If I add a new task directly to my "today view" and manually put it somewhere other then the bottom:

  • The lenth of api.state["day_orders"] doesn't change (but its 250 for me)
  • one item gets replaced by the created task
  • the browser-data include a "day_order" timestamp. Maybe thats what they're using in the client to figure out what task to replace...

image

... I hope for others to bring light to this behavior

@silentjay silentjay changed the title day_order always returns -1 api.state['day_orders'] broken? Dec 6, 2020
@caiocarrara
Copy link

Hello, @silentjay and @6uhrmittag 👋 Caio here. I'm a Doist developer.

item.day_order returns an integer of where a task sits in the queue in relation to other tasks in the Today view.

Yes. This is correct.

However in my case where i'm using a custom sort for the web apps Today view the tasks day_order always return -1.

If I understood correctly, you are sorting your Today view with the recent released sort and grouping options. If so, this sort and grouping options do not affect tasks day order attribute. The fact your tasks return with -1 means that they were never sorted manually on Today view. -1 can be understood as "no manual order". As soon as you change any task order manually on Today view, all the tasks will receive a day order.

However in my case api.state['day_orders'] returns 257 items, while the actual tasks due today are 52.

This looks like a misbehavior. I'll further check it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants