Skip to content

Commit

Permalink
Merge pull request #7 from mtscanlan/fix-recursive-hasattr
Browse files Browse the repository at this point in the history
1758 : fix recursive hasattr call
  • Loading branch information
aaront committed Apr 10, 2022
2 parents db97f46 + cf14fde commit 0ea1b2e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion mygeotab/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ def object_serializer(obj):
:param obj: The object.
"""
return dates.format_iso_datetime(obj) if hasattr(obj, "isoformat") else obj
if hasattr(obj, 'isoformat'):
return dates.format_iso_datetime(obj)
else:
# Let the base class default method raise the TypeError
return json.JSONEncoder.default(obj)


def object_deserializer(obj):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import json
from datetime import date, datetime

import pytest
import pytz

from mygeotab import serializers, dates
Expand Down Expand Up @@ -42,6 +43,10 @@ def test_only_date(self):
data_str = json_serialize(data)
assert data_str == expected_str

def test_unparsable_data_throws(self):
with pytest.raises(TypeError):
json_serialize({''})


class TestDeserialization:
def test_top_level_datetime(self):
Expand Down

0 comments on commit 0ea1b2e

Please sign in to comment.