mirror of
https://github.com/bspeice/metrik
synced 2024-11-23 07:38:09 -05:00
Idiot forgot datetime was immutable
This commit is contained in:
parent
061b4256fd
commit
a44635c660
@ -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
|
||||||
|
@ -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'])
|
Loading…
Reference in New Issue
Block a user