1
0
mirror of https://github.com/bspeice/metrik synced 2024-11-04 22:48:11 -05:00

Idiot forgot datetime was immutable

This commit is contained in:
bspeice 2016-09-06 21:15:36 -04:00
parent 061b4256fd
commit a44635c660
2 changed files with 4 additions and 5 deletions

View File

@ -38,8 +38,7 @@ class MongoTarget(Target):
# Because MongoDB isn't microsecond-accurate, we need to set the # Because MongoDB isn't microsecond-accurate, we need to set the
# microseconds to 0 to ensure consistency # microseconds to 0 to ensure consistency
present_deref = present if present is not None else datetime.now() present_deref = present if present is not None else datetime.now()
present_deref.replace(microsecond=0) id_dict['_created_at'] = present_deref.replace(microsecond=0)
id_dict['_created_at'] = present_deref
with self.get_db() as db: with self.get_db() as db:
return db[self.collection].insert_one(id_dict).inserted_id return db[self.collection].insert_one(id_dict).inserted_id

View File

@ -54,8 +54,8 @@ class MongoTargetTest(MongoTest):
r = t.retrieve() r = t.retrieve()
self.assertGreaterEqual(present, r['_created_at']) self.assertGreaterEqual(present, r['_created_at'])
one_second_past = present - timedelta(seconds=1) second_prior = (present - timedelta(seconds=1)).replace(microsecond=0)
t = MongoTarget('test_collection', 1235) t = MongoTarget('test_collection', 1235)
t.persist({}, present=one_second_past) t.persist({}, present=second_prior)
r = t.retrieve() r = t.retrieve()
self.assertEqual(one_second_past, r['_created_at']) self.assertEqual(second_prior, r['_created_at'])