Skip to content
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

Protocols trait support #3376

Merged
merged 12 commits into from
Feb 12, 2025
Merged

Conversation

SamRemis
Copy link
Contributor

@SamRemis SamRemis commented Feb 4, 2025

This PR adds support for the new protocols trait, which allows a service to list a number of protocols it supports; botocore will automatically choose the highest priority supported protocol and use that to make requests to the service.

@codecov-commenter
Copy link

codecov-commenter commented Feb 4, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (develop@19140a9). Learn more about missing BASE report.
Report is 191 commits behind head on develop.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #3376   +/-   ##
==========================================
  Coverage           ?   93.05%           
==========================================
  Files              ?       66           
  Lines              ?    14491           
  Branches           ?        0           
==========================================
  Hits               ?    13485           
  Misses             ?     1006           
  Partials           ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

Looks great so far! I left a few suggestions, but nothing major.

botocore/args.py Outdated
def _resolve_protocol(self, service_model):
# If a service does not have a `protocols` trait, fall back to the legacy
# `protocol` trait
if 'protocols' not in service_model.metadata:
Copy link
Contributor

Choose a reason for hiding this comment

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

This one feels a little odd to me. We may want to be validating the truthiness of protocols rather than the key existing. It should be equivalent or a supeset of protocols, but if it's [] and protocol exists, it seems better to be using the protocol instead of hard failing?

Copy link
Contributor Author

@SamRemis SamRemis Feb 6, 2025

Choose a reason for hiding this comment

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

I don't think we can access any of the new CachedProperty properties directly unless we are somehow guaranteed they will be there in all models. This guarantee is impossible because some users have custom models, so we will always need some way to fall back to the existing properties. The reason is that when we access any of these properties- service_model.protocols for instance, it calls _get_metadata_property under the hood, which will raise an error if the key doesn't exist:

    def _get_metadata_property(self, name):
        try:
            return self.metadata[name]
        except KeyError:
            raise UndefinedModelAttributeError(
                f'"{name}" not defined in the metadata of the model: {self}'
            )

Also, while I'm not sure how we could get into the codepath where properties is an empty array given that we have a test below that prevents that, I think that the readability of this code could be improved by Nate's suggestion, so I'll go make that change and push up a revision shortly :)

I'm not sure that there's a way to safely call service_model.protocols directly though, so I'll have to do it through service_model.metadata.get('protocol')

Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

I have some pretty minor feedback. Happy to approve once they've been addressed or we talk about why they shouldn't.

services_models_with_protocols.append(service_model)
else:
services_models_without_protocols.append(service_model)
return (services_models_with_protocols, services_models_without_protocols)
Copy link
Contributor

Choose a reason for hiding this comment

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

[Not Blocking]This seems pretty memory inefficient as opposed to using yield. I don't feel strongly though given this pattern is used in other tests and this isn't actually SDK code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to something "better"? It doesn't load them all into memory, but it feels a bit awkward. I'd love some feedback on it when you get the chance.

@SamRemis SamRemis force-pushed the protocols-trait-support branch from f51ee8e to 653e512 Compare February 11, 2025 01:57
Copy link
Contributor

@jonathan343 jonathan343 left a comment

Choose a reason for hiding this comment

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

LGTM!

@SamRemis SamRemis merged commit ee519c7 into boto:develop Feb 12, 2025
40 checks passed
aws-sdk-python-automation added a commit that referenced this pull request Feb 12, 2025
* release-1.36.19:
  Bumping version to 1.36.19
  Update to latest models
  Protocols trait support (#3376)
hswong3i pushed a commit to alvistack/boto-botocore that referenced this pull request Feb 13, 2025
Add support for protocols trait
Co-authored-by: jonathan343 <[email protected]>
Co-authored-by: Nate Prewitt <[email protected]>
SamRemis added a commit to SamRemis/botocore that referenced this pull request Feb 18, 2025
Add support for protocols trait
Co-authored-by: jonathan343 <[email protected]>
Co-authored-by: Nate Prewitt <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants