From d46899943cafcc5be3c0bcdb36945c090511c667 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Tue, 24 Sep 2019 15:38:33 +1000 Subject: [PATCH] fix negative due dates in filtered decks https://anki.tenderapp.com/discussions/ankidesktop/35978-rebuilding-filtered-deck-on-experimental-v2-empties-deck-and-reschedules-to-the-year-1745 this means affected cards will not have the selected ordering applied, but that seems preferable to the alternatives --- anki/schedv2.py | 4 +++- tests/test_schedv2.py | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/anki/schedv2.py b/anki/schedv2.py index 33964db69..e18f3cdc9 100644 --- a/anki/schedv2.py +++ b/anki/schedv2.py @@ -1079,7 +1079,9 @@ due = (case when odue>0 then odue else due end), odue = 0, odid = 0, usn = ? whe query = """ update cards set odid = did, odue = due, -did = ?, due = ?, usn = ? +did = ?, +due = (case when due <= 0 then due else ? end), +usn = ? %s where id = ? """ % queue diff --git a/tests/test_schedv2.py b/tests/test_schedv2.py index 078cea804..7e217334c 100644 --- a/tests/test_schedv2.py +++ b/tests/test_schedv2.py @@ -1179,3 +1179,28 @@ def test_moveVersions(): col.changeSchedulerVer(1) c.load() assert c.due == 50 + +# cards with a due date earlier than the collection should retain +# their due date when removed +def test_negativeDueFilter(): + d = getEmptyCol() + + # card due prior to collection date + f = d.newNote() + f['Front'] = "one"; f['Back'] = "two" + d.addNote(f) + c = f.cards()[0] + c.due = -5 + c.queue = 2 + c.ivl = 5 + c.flush() + + # into and out of filtered deck + did = d.decks.newDyn("Cram") + d.sched.rebuildDyn(did) + d.sched.emptyDyn(did) + d.reset() + + c.load() + assert c.due == -5 +