Skip to content

Commit 8938148

Browse files
Michael Brewerheitorlessa
Michael Brewer
andauthored
fix: use geattr over hasattr
hasattr doesn't work in the way you might think it does - it's a misnomer in Python, really. It'll effectively do a blanket try/except, throw the results away, and specially in this case it'll access all getters from data -- the more getters the worse the performance. Co-authored-by: Heitor Lessa <[email protected]>
1 parent 4ed708a commit 8938148

File tree

1 file changed

+1
-2
lines changed
  • aws_lambda_powertools/utilities/idempotency/persistence

1 file changed

+1
-2
lines changed

aws_lambda_powertools/utilities/idempotency/persistence/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ def _generate_hash(self, data: Any) -> str:
224224
Hashed representation of the provided data
225225
226226
"""
227-
if hasattr(data, "raw_event"):
228-
data = data.raw_event
227+
data = getattr(data, "raw_event", data) # could be a data class depending on decorator order
229228
hashed_data = self.hash_function(json.dumps(data, cls=Encoder).encode())
230229
return hashed_data.hexdigest()
231230

0 commit comments

Comments
 (0)