-
-
Notifications
You must be signed in to change notification settings - Fork 185
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
Moto integration #1004
Moto integration #1004
Conversation
Pipfile
Outdated
@@ -18,6 +18,7 @@ pytest = "==6.2.4" | |||
pytest-cov = "==2.11.1" | |||
pytest-asyncio = "==0.14.0" | |||
pytest-xdist = "==2.2.1" | |||
s3fs = "==2023.3.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this introduces a circular dependency, can't do it as it may later be incompatible with the version of aiobotocore this becomes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Removed the dependency, used paginator
for testing instead
'headers': HTTPHeaderDict( | ||
{ | ||
k.decode('utf-8').lower(): v.decode('utf-8') | ||
for k, v in http_response.raw.raw_headers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's important we use raw_headers as the non-raw doesn't preserve casing of the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, the alternative is kind of an ugly patch. Let me know what ya think
@thehesiod any update on this? |
re NOTE in your description you need to run with |
@@ -1,5 +1,9 @@ | |||
Changes | |||
------- | |||
2.5.1 (2023-04-05) | |||
^^^^^^^^^^^^^^^^^^ | |||
* integrate moto |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is more of add support for moto in-place mock methods
@@ -13,6 +14,8 @@ | |||
logger, | |||
) | |||
from botocore.hooks import first_non_none_response | |||
from botocore.utils import lowercase_dict | |||
from moto.core.botocore_stubber import MockRawResponse |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moto is not a dependency of this library, so you can't do this. I think this is really a bug in moto, it needs support for aiobotocore. If you were to do this it would need to be a try/except ImportError. Another option would be for aiobotocore to expose some moto helpers that correctly patch the response. I'd do that instead as it will be a lot cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moto is not a dependency of this library, so you can't do this.
Ack! I missed that!
I'm a little busy this week but I'll try to sneak in some time to dig into moto repo and see if there's a cleaner solution to this. I tried sending encoded raw_headers
here and it broke a bunch of tests. Let me try that again and see
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries, thanks for working on this
sorry for delay, I think either moto needs to add async patches, or we ship like a moto_helpers.py which does the right thing. |
Closing this to avoid piling on irrelevant commits. See #1007 |
Description of Change
PR adds a patch to
endpoint.convert_to_response_dict
such that it can work with moto while not changing the expected behavior of the method. I also added tests to replicate the problem and fix the issue.Issue (#979)
The primary problem with moto integration is this method. There are 2 main issues with that method
raw
to haveraw_headers
just to convert the headers to lowercase.await
.How to reproduce the error
Resolution
It's a two part solution
1. Remove the need forraw_headers
and use the headers directly usingbotocore.utils.lowercase_dict
raw_headers
are necessary, I've created a check to use headers if thehttpresponse
came from motoawait
forawaitable
objects. This check can be done usinginspect.isawaitable
Assumptions
1. This patch was added only to convert to lowercase and this botocore util does the same^Not valid anymore since
raw_headers
remainAlternative methods considered
I considered added a raw_headers to MockRawResponse but it seemed unnecessary especially if the point to convert to lowercase based on the comment
Checklist for All Submissions
Checklist when updating botocore and/or aiohttp versions
I've been getting
botocore.exceptions.NoCredentialsError: Unable to locate credentials
for some of the tests (5 to be exact). Ive got them even before I made changes, so I'm unsure if I'm breaking anything with this PR