zeitgeist team mailing list archive
-
zeitgeist team
-
Mailing list archive
-
Message #02388
[Merge] lp:~zeitgeist/zeitgeist/fix-673916-GetEvent-duplicate-id into lp:zeitgeist
Markus Korn has proposed merging lp:~zeitgeist/zeitgeist/fix-673916-GetEvent-duplicate-id into lp:zeitgeist.
Requested reviews:
Zeitgeist Framework Team (zeitgeist)
Related bugs:
#673916 ZeitgeistEngine.get_events() returns wrong result if there are duplicates in the ids argument
https://bugs.launchpad.net/bugs/673916
ZeitgeistEngine.get_events() now maps event objects correctly to its ids if
the method was called with duplicate ids (LP: #673916)
--
https://code.launchpad.net/~zeitgeist/zeitgeist/fix-673916-GetEvent-duplicate-id/+merge/40655
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~zeitgeist/zeitgeist/fix-673916-GetEvent-duplicate-id into lp:zeitgeist.
=== modified file '_zeitgeist/engine/main.py'
--- _zeitgeist/engine/main.py 2010-11-11 08:16:53 +0000
+++ _zeitgeist/engine/main.py 2010-11-11 18:48:48 +0000
@@ -173,7 +173,9 @@
else:
ids = (row[0] for row in rows)
- id_hash = dict((id, n) for n, id in enumerate(ids))
+ id_hash = defaultdict(list)
+ for n, id in enumerate(ids):
+ id_hash[id].append(n)
# If we are not able to get an event by the given id
# append None instead of raising an Error. The client
@@ -195,7 +197,8 @@
event.append_subject(self._get_subject_from_row(row))
event = self.extensions.apply_get_hooks(event, sender)
if event is not None:
- sorted_events[id_hash[event.id]] = event
+ for n in id_hash[event.id]:
+ sorted_events[n] = event
log.debug("Got %d events in %fs" % (len(sorted_events), time.time()-t))
return sorted_events
=== modified file 'test/engine-test.py'
--- test/engine-test.py 2010-11-10 14:44:08 +0000
+++ test/engine-test.py 2010-11-11 18:48:48 +0000
@@ -212,6 +212,12 @@
self.assertEquals(3, len(events))
for ev in events : self.assertEquals(None, ev)
+ def testGetDuplicateEventIds(self):
+ import_events("test/data/five_events.js", self.engine)
+ events = self.engine.get_events([1, 1])
+ self.assertEqual(2, len(events))
+ self.assertEqual(2, len(filter(None, events)))
+
def testFindEventsId(self):
global test_event_1
self.testSingleInsertGet()
Follow ups