Skip to content

Commit

Permalink
Merge pull request #28 from RSS-Engineering/ttl-field-fixes
Browse files Browse the repository at this point in the history
Ttl field fixes
  • Loading branch information
KevinKlaesRackspace authored Jan 23, 2025
2 parents 882c74b + 57d0eb6 commit e2b276f
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pydanticrud/backends/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,14 @@ def rule_to_boto_expression(rule: Rule, keys: Optional[Set[str]] = None):
"bool": "BOOL",
}

EPOCH = datetime(1970, 1, 1, 0, 0)


def _to_epoch_decimal(dt: datetime) -> Decimal:
def _to_epoch_decimal(dt: Union[datetime, float]) -> Decimal:
"""TTL fields must be stored as a float but boto only supports decimals."""
epock = EPOCH
if dt.tzinfo:
epock = epock.replace(tzinfo=timezone.utc)
return Decimal((dt - epock).total_seconds())
if type(dt) is datetime:
val = dt.timestamp()
else:
val = dt
return Decimal(val)


SERIALIZE_MAP = {
Expand Down

0 comments on commit e2b276f

Please sign in to comment.