Disallow duplicate heartbeats and crashreports
Add unique constraints and corresponding schema and data migration.
Adapt all test cases so that only unique heartbeats and crashreports
are sent. Delete test cases that are inappropriate as no duplicate
entries can exist in the database anymore.
Issue: HIC-180
Change-Id: I768d1610d4482c9d61b76cdbc588334198bfe415
diff --git a/crashreport_stats/rest_endpoints.py b/crashreport_stats/rest_endpoints.py
index ba8ea9f..a15edf5 100644
--- a/crashreport_stats/rest_endpoints.py
+++ b/crashreport_stats/rest_endpoints.py
@@ -189,7 +189,7 @@
device_heartbeats = list(device.heartbeats.all())
device_crashreports = list(device.crashreports.all())
- dates = {heartbeat.date.date() for heartbeat in device_heartbeats}
+ dates = {heartbeat.date for heartbeat in device_heartbeats}
response = [
get_stats_for_date(date, device_crashreports, device_heartbeats)
@@ -201,7 +201,7 @@
def get_stats_for_date(date, crashreports, heartbeats):
"""Get the stats for a device for a specific date."""
- heartbeats = filter_instances(heartbeats, lambda hb: hb.date.date() == date)
+ heartbeats = filter_instances(heartbeats, lambda hb: hb.date == date)
crashreports = filter_instances(
crashreports, lambda c: c.date.date() == date
)