trim_snapshots() raises ValueError exception when start time of a snapshot has milliseconds
jun66j5 opened this issue · comments
I encountered ValueError
from trim_snapshots()
. Investigating, the error occurs when start time of a snapshot has milliseconds.
>>> import boto
>>> boto.__version__
'2.49.0'
>>> conn = boto.connect_ec2()
>>> all_snapshots = conn.get_all_snapshots(owner = 'self')
>>> all_snapshots.sort(key=lambda s: s.start_time)
>>> all_snapshots[0].start_time
u'2015-09-22T05:29:04.000Z'
>>> all_snapshots[-1].start_time
u'2019-05-08T03:29:02.343Z'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/venv/lib/python2.6/site-packages/boto/ec2/connection.py", line 2680, in trim_snapshots
'%Y-%m-%dT%H:%M:%S.000Z')
File "/usr/lib64/python2.6/_strptime.py", line 325, in _strptime
(data_string, format))
ValueError: time data '2019-05-07T04:29:02.604Z' does not match format '%Y-%m-%dT%H:%M:%S.000Z'
I think %f
should be used for datetime.strptime
like this.
+++ a/boto/ec2/connection.py 2019-04-11 20:40:56.000000000 +0900
--- b/boto/ec2/connection.py 2019-05-08 12:41:32.000000000 +0900
@@ -2677,7 +2677,7 @@
check_this_snap = True
while check_this_snap and time_period_number < target_backup_times.__len__():
snap_date = datetime.strptime(snap.start_time,
+ '%Y-%m-%dT%H:%M:%S.000Z')
- '%Y-%m-%dT%H:%M:%S.%fZ')
if snap_date < target_backup_times[time_period_number]:
# the snap date is before the cutoff date.
# Figure out if it's the first snap in this
Charles Morin
Same. Verified this fixes it as well.