From 061b4256fd2bd5e2f3a43260cdd009dbd5192981 Mon Sep 17 00:00:00 2001 From: bspeice Date: Tue, 6 Sep 2016 21:07:59 -0400 Subject: [PATCH] Fix microsecond-level issues --- metrik/targets/mongo.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/metrik/targets/mongo.py b/metrik/targets/mongo.py index d2064ce..f941291 100644 --- a/metrik/targets/mongo.py +++ b/metrik/targets/mongo.py @@ -34,8 +34,12 @@ class MongoTarget(Target): id_dict = dict_object id_dict['_id'] = self.id id_dict['_metrik_version'] = version - id_dict['_created_at'] = (present if present is not None - else datetime.now()) + + # Because MongoDB isn't microsecond-accurate, we need to set the + # microseconds to 0 to ensure consistency + present_deref = present if present is not None else datetime.now() + present_deref.replace(microsecond=0) + id_dict['_created_at'] = present_deref with self.get_db() as db: return db[self.collection].insert_one(id_dict).inserted_id