Avoid calling checkValid on an empty note

Fix error message when editFocusLost is called after editor destruction

https://anki.tenderapp.com/discussions/ankidesktop/11175-bug-in-browser-revealed-by-add-on?unresolve=true
To reproduce:
1. Install the attached add-on. (All it does is register a function on the editFocusLost hook, and set the flag to 1 to signify that a field has been updated).
2. Run Anki. Enter the Browse window. Press Enter to display your deck.
3. Select one card.
4. Click inside one of the fields for that card. Now, when you leave that field, the editFocusLost hook will be called.
5. Now, select 2 notes from the browser, with your mouse, without clicking anywhere else before.

You will observe this error message:

Traceback (most recent call last):
File "aqt/progress.pyc", line 69, in handler 
File "aqt/editor.pyc", line 467, in onUpdate 
File "aqt/editor.pyc", line 572, in checkValid AttributeError: 'NoneType' object has no attribute 'fields'
This commit is contained in:
Thomas TEMPÉ 2014-12-31 22:36:12 +08:00
parent b1ecdba42f
commit 3d81ef2c68

View file

@ -462,6 +462,8 @@ class Editor(object):
"editFocusLost", False, self.note, self.currentField): "editFocusLost", False, self.note, self.currentField):
# something updated the note; schedule reload # something updated the note; schedule reload
def onUpdate(): def onUpdate():
if not self.note:
return
self.stealFocus = True self.stealFocus = True
self.loadNote() self.loadNote()
self.checkValid() self.checkValid()