Mw.col.sched.deck_due_tree() works in debug mode but not in addon

Hello, I’m trying to use the following code:

a = mw.col.sched.deck_due_tree().review_count

b = mw.col.sched.deck_due_tree().learn_count

c = mw.col.sched.deck_due_tree().new_count

total = a + b + c

print(total)

It works in debug mode but not in my addon.

It gives the following error:
mw.col.sched.deck_due_tree()

AttributeError: ‘NoneType’ object has no attribute ‘sched’

You need to ensure that the collection is initialized before accessing col. Try the aqt.gui_hooks.main_window_did_init hook. E.g:

from aqt import gui_hooks

def func():
    due_tree = mw.col.sched.deck_due_tree()

gui_hooks.main_window_did_init.append(func)
3 Likes