Skip to content

Commit 45c632e

Browse files
Change how TTL field is handled and don't always force it to be modified
1 parent 882c74b commit 45c632e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

pydanticrud/backends/dynamodb.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,14 @@ def rule_to_boto_expression(rule: Rule, keys: Optional[Set[str]] = None):
7171
"bool": "BOOL",
7272
}
7373

74-
EPOCH = datetime(1970, 1, 1, 0, 0)
7574

76-
77-
def _to_epoch_decimal(dt: datetime) -> Decimal:
75+
def _to_epoch_decimal(dt: datetime | float) -> Decimal:
7876
"""TTL fields must be stored as a float but boto only supports decimals."""
79-
epock = EPOCH
80-
if dt.tzinfo:
81-
epock = epock.replace(tzinfo=timezone.utc)
82-
return Decimal((dt - epock).total_seconds())
77+
if type(dt) is datetime:
78+
val = dt.timestamp()
79+
else:
80+
val = dt
81+
return Decimal(val)
8382

8483

8584
SERIALIZE_MAP = {

0 commit comments

Comments
 (0)