Skip to content

Commit

Permalink
fix case of table not exists and item not exists
Browse files Browse the repository at this point in the history
  • Loading branch information
idocyabra committed Aug 13, 2024
1 parent dcffafc commit 67a80a3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/flask_session/dynamodb/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ def _create_table(self):

def _retrieve_session_data(self, store_id: str) -> Optional[dict]:
# Get the saved session (document) from the database
document = self.store.get_item(Key={"id": store_id}).get("Item")
session_is_not_expired = Decimal(datetime.utcnow().timestamp()) <= document.get(
try:
document = self.store.get_item(Key={"id": store_id}).get("Item")
except self.client.meta.client.exceptions.ResourceNotFoundException:
return None

if document and Decimal(datetime.utcnow().timestamp()) <= document.get(
"expiration"
)
if document and session_is_not_expired:
):
serialized_session_data = want_bytes(document.get("val").value)
return self.serializer.loads(serialized_session_data)
return None
Expand Down

0 comments on commit 67a80a3

Please sign in to comment.