Could ParamValidation be more permissive?
See original GitHub issueThere’s a common pattern in python where you want to provide all parameters as a value or None, and expect that the receiving end treats “None” as a non-value.
The pattern simplifies and shortens code. Unfortunately it doesn’t seem possible to do so with boto3:
ec2 = boto3.resource('ec2', args.region)
volume = ec2.create_volume(
Size=int(args.size),
SnapshotId=args.snapshot_id or None,
AvailabilityZone=instance.placement['AvailabilityZone'],
VolumeType=args.volume_type,
Iops=args.iops or None,
Encrypted=bool(args.encrypted),
KmsKeyId=args.encrypted or None)
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter Iops, value: None, type: <type 'NoneType'>, valid types: <type 'int'>, <type 'long'>
Invalid type for parameter KmsKeyId, value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>
Invalid type for parameter SnapshotId, value: None, type: <type 'NoneType'>, valid types: <type 'basestring'>
Instead, one has to carefully build a dict with the arguments using one if
per argument:
opt = {}
if args.iops:
opt['Iops'] = args.iops
if args.kms_key_id:
opt['KmsKeyId'] = args.kms_key_id
# ...
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Wikimedia\ParamValidator\ParamValidator Class Reference
A list of standard type names and types that may be passed as $typeDefs to __construct(). More ... The rest of the code...
Read more >Permissive vs. Strict API Message validation
Permissive vs. Strict REST API. It seems to me that your question isn't really about REST; similar concerns arise in other messaging systems ......
Read more >Class: AWS.Iot — AWS SDK for JavaScript
Constructs a service interface object. Each API operation is exposed as a function on service. Service Description.
Read more >Plugtest 2021: Specification discussion ...
Is a more appropriate action to ignore the unknown parameter? ... discussed at the ISG level API implementation can be strict or permissive....
Read more >aws-sdk | Yarn - Package Manager
For more information see the Developer Guide or API Reference. For release notes, see the CHANGELOG. Prior to v2.4.8, release notes can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Wanted to chime in here and indicate my support of this change as well.
I’m in the process of porting some saltstack states to boto3 and this issue is definitely a huge pain. Would not be a big deal if you only cared about a few of the possible parameters, but adds quite a bit of code to deal with support for None on the optionals.
Would make more sense to me to force the corner cases mentioned by @rayluo in #331 to jump through some hoops rather than every common use case.
Coming back to this, the logic in the previously linked ticket #331 is correct. We can’t make this change because the absence of a parameter and that parameter being
None
aren’t always the same. Considering that these parameters get serialized down to an API call (commonly JSON) the following aren’t equal:Which could potentially be an important distinction for some APIs.