diff options
author | Aurélien Bompard <aurelien@bompard.org> | 2013-01-09 15:24:28 +0100 |
---|---|---|
committer | Aurélien Bompard <aurelien@bompard.org> | 2013-01-09 15:24:43 +0100 |
commit | b1961c46287ab5c85af24ec5a4424e5fb58a3a30 (patch) | |
tree | cad781e8f653f35d32b005b82ab8211569e1ff59 | |
parent | 9dcdaaee79418541514aa6aaac6d7400f792b731 (diff) | |
download | kittystore-b1961c46287ab5c85af24ec5a4424e5fb58a3a30.tar.gz kittystore-b1961c46287ab5c85af24ec5a4424e5fb58a3a30.tar.xz kittystore-b1961c46287ab5c85af24ec5a4424e5fb58a3a30.zip |
Don't crash updating a thread's date when it has no msg yet
-rw-r--r-- | kittystore/storm/model.py | 8 | ||||
-rw-r--r-- | kittystore/test/test_storm_model.py | 5 |
2 files changed, 11 insertions, 2 deletions
diff --git a/kittystore/storm/model.py b/kittystore/storm/model.py index f0596ea..a77f756 100644 --- a/kittystore/storm/model.py +++ b/kittystore/storm/model.py @@ -216,5 +216,9 @@ class Thread(Storm): """Auto-set the active date from the last email in thread""" if self.date_active is not None: return - self.date_active = list(self.emails.order_by(Desc(Email.date) - ).config(limit=1).values(Email.date))[0] + email_dates = list(self.emails.order_by(Desc(Email.date) + ).config(limit=1).values(Email.date)) + if email_dates: + self.date_active = email_dates[0] + else: + self.date_active = datetime.datetime.now() diff --git a/kittystore/test/test_storm_model.py b/kittystore/test/test_storm_model.py index 38ba6c2..c1507c1 100644 --- a/kittystore/test/test_storm_model.py +++ b/kittystore/test/test_storm_model.py @@ -89,3 +89,8 @@ class TestStormModel(unittest.TestCase): self.store.add_to_list(ml, msg) thread = self.store.db.find(Thread).one() self.assertEqual(thread.subject, "Dummy subject") + + def test_thread_no_email(self): + thread = Thread("example-list", "<msg1>") + self.store.db.add(thread) + self.store.flush() |