diff --git a/src/flask_session/dynamodb/dynamodb.py b/src/flask_session/dynamodb/dynamodb.py index a7d4e3a0..b2fb223e 100644 --- a/src/flask_session/dynamodb/dynamodb.py +++ b/src/flask_session/dynamodb/dynamodb.py @@ -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