Skip to content

Commit

Permalink
Fix: utils.clean must not pop date values
Browse files Browse the repository at this point in the history
  • Loading branch information
hadrien committed May 8, 2017
1 parent d4ac5b6 commit 6efac2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 6 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Next release
============

* [Fix](https://github.com/segmentio/analytics-python/issues/94): Date objects
are not removed from event dicts during cleanup.


1.2.7 / 2017-01-31
==================
Expand Down
9 changes: 8 additions & 1 deletion analytics/test/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import date, datetime, timedelta
from decimal import Decimal
import unittest

Expand Down Expand Up @@ -49,6 +49,13 @@ def test_clean(self):
utils.clean(combined)
self.assertEqual(combined.keys(), pre_clean_keys)

def test_clean_with_dates(self):
dict_with_dates = {
'birthdate': date(1980, 1, 1),
'registration': datetime.utcnow(),
}
self.assertEqual(dict_with_dates, utils.clean(dict_with_dates))

def test_bytes(self):
if six.PY3:
item = bytes(10)
Expand Down
4 changes: 2 additions & 2 deletions analytics/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dateutil.tz import tzlocal, tzutc
from datetime import datetime
from datetime import date, datetime
from decimal import Decimal
import logging
import numbers
Expand Down Expand Up @@ -38,7 +38,7 @@ def clean(item):
if isinstance(item, Decimal):
return float(item)
elif isinstance(item, (six.string_types, bool, numbers.Number, datetime,
type(None))):
date, type(None))):
return item
elif isinstance(item, (set, list, tuple)):
return _clean_list(item)
Expand Down

0 comments on commit 6efac2e

Please sign in to comment.