Skip to content

Commit

Permalink
Fix Timedelta*Attribute serialization (#41)
Browse files Browse the repository at this point in the history
In DynamoDB API, number ("N") data type must be serialized as a JSON string.
  • Loading branch information
ikonst authored Apr 12, 2022
1 parent b6e9ff8 commit c9c8493
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pynamodb_attributes/timedelta.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class TimedeltaAttribute(Attribute[timedelta]):
def deserialize(self, value: str) -> timedelta:
return timedelta(microseconds=float(value) * (1000000.0 / self._multiplier))

def serialize(self, td: timedelta) -> int:
return int(td.total_seconds() * self._multiplier)
def serialize(self, td: timedelta) -> str:
return str(int(td.total_seconds() * self._multiplier))

def __set__(self, instance: Any, value: Optional[Any]) -> None:
if value is not None and not isinstance(value, timedelta):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name="pynamodb-attributes",
version="0.3.1",
version="0.3.2",
description="Common attributes for PynamoDB",
url="https://www.github.com/lyft/pynamodb-attributes",
maintainer="Lyft",
Expand Down

0 comments on commit c9c8493

Please sign in to comment.