Skip to content

fix(idempotency): TypeError when calling is_missing_idempotency_key with an int #315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

michaelbrewer
Copy link
Contributor

@michaelbrewer michaelbrewer commented Mar 7, 2021

Description of changes:

Fix for is_missing_idempotency_key which can raise a TypeError: 'int' object is not iterable
for the follow code

BasePersistenceLayer.is_missing_idempotency_key(1000)

Checklist

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Fix for: TypeError: 'int' object is not iterable
@michaelbrewer michaelbrewer changed the title fix(idempotency): is_missing_idempotency_key and int fix(idempotency): TypeError calling is_missing_idempotency_key with an int Mar 7, 2021
@michaelbrewer michaelbrewer changed the title fix(idempotency): TypeError calling is_missing_idempotency_key with an int fix(idempotency): TypeError when calling is_missing_idempotency_key with an int Mar 7, 2021
Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch! One minor thing to break that into a multi-line statement as that would've been easier to spot this issue too.

@@ -183,7 +183,7 @@ def _get_hashed_idempotency_key(self, lambda_event: Dict[str, Any]) -> str:

@staticmethod
def is_missing_idempotency_key(data) -> bool:
return data is None or not data or all(x is None for x in data)
return data is None or not data or (type(data).__name__ in ("tuple", "list") and all(x is None for x in data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we break this into a multi-line thing?

It's quite complex now and we might find another bug here in the future I'm sure

@heitorlessa heitorlessa added bug Something isn't working area/utilities labels Mar 7, 2021
@codecov-io
Copy link

codecov-io commented Mar 7, 2021

Codecov Report

Merging #315 (f935e69) into develop (bc17b5f) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #315   +/-   ##
========================================
  Coverage    99.88%   99.88%           
========================================
  Files           91       91           
  Lines         3339     3341    +2     
  Branches       162      163    +1     
========================================
+ Hits          3335     3337    +2     
  Misses           2        2           
  Partials         2        2           
Impacted Files Coverage Δ
...wertools/utilities/idempotency/persistence/base.py 99.35% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bc17b5f...f935e69. Read the comment docs.

Copy link
Contributor

@heitorlessa heitorlessa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Control flow simplification with two Ifs

@heitorlessa heitorlessa merged commit 5ff76b7 into aws-powertools:develop Mar 7, 2021
@michaelbrewer
Copy link
Contributor Author

@heitorlessa funny way of doing it:

assert type(None).__name__ == "NoneType"

@michaelbrewer michaelbrewer deleted the fix-idempotent-missing-key-check branch March 7, 2021 08:08
@heitorlessa
Copy link
Contributor

heitorlessa commented Mar 7, 2021 via email

heitorlessa added a commit that referenced this pull request Mar 9, 2021
…tools-python into develop

* 'develop' of https://github.com/awslabs/aws-lambda-powertools-python:
  feat(logging): Include exception_name (#320)
  chore: remove gatsby mention as migrated completed
  refactor(parameters): Consistently reference env (#319)
  docs(metrics): remove minimum dimensions
  docs: Correct code examples (#317)
  docs(metrics): Correct code examples in markdown (#316)
  fix(idempotency): TypeError when calling is_missing_idempotency_key with an int (#315)
  docs(metrics): Corrections to the code examples (#314)
  fix(idempotency): Correctly handle save_inprogress errors (#313)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants