`AttributeNames` argument of `.receive_messages()` has incorrect type.
Describe the bug
The AttributeNames argument of .receive_messages() is currently typed as Sequence[QueueAttributeNameType] but it seems that Sequence[MessageSystemAttributeNameType | QueueAttributeNameType] would be a better fit. Looking at the documentation we can see that the "Request Syntax" section shows only all of the values listed in QueueAttributeNameType, but below under the "Parameters" section it lists all of the values of MessageSystemAttributeNameType plus only All and SqsManagedSseEnabled from QueueAttributeNameType.
Looking through to the API Reference it seems to list all of these attributes under "AttributeName.N", but in two distinct blocks 🤷🏻
To Reproduce Steps to reproduce the behavior:
- Install
boto3-stubs[sqs]==1.24.38 - Run
mypyon the following code sample
import boto3
from mypy_boto3_sqs import SQSClient
client: SQSClient = boto3.client("sqs")
client.receive_message(
QueueUrl="...",
AttributeNames=["ApproximateReceiveCount", "SentTimestamp"],
)
Actual output
bug.py:7: error: List item 0 has incompatible type "Literal['ApproximateReceiveCount']"; expected
"Literal['All', 'ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesDelayed', 'ApproximateNumberOfMessagesNotVisible', 'ContentBasedDeduplication', 'CreatedTimestamp', 'DeduplicationScope', 'DelaySeconds', 'FifoQueue', 'FifoThroughputLimit', 'KmsDataKeyReusePeriodSeconds', 'KmsMasterKeyId', 'LastModifiedTimestamp', 'MaximumMessageSize', 'MessageRetentionPeriod', 'Policy', 'QueueArn', 'ReceiveMessageWaitTimeSeconds', 'RedriveAllowPolicy', 'RedrivePolicy', 'SqsManagedSseEnabled', 'VisibilityTimeout']"
[list-item]
AttributeNames=["ApproximateReceiveCount", "SentTimestamp"],
^
bug.py:7: error: List item 1 has incompatible type "Literal['SentTimestamp']"; expected
"Literal['All', 'ApproximateNumberOfMessages', 'ApproximateNumberOfMessagesDelayed', 'ApproximateNumberOfMessagesNotVisible', 'ContentBasedDeduplication', 'CreatedTimestamp', 'DeduplicationScope', 'DelaySeconds', 'FifoQueue', 'FifoThroughputLimit', 'KmsDataKeyReusePeriodSeconds', 'KmsMasterKeyId', 'LastModifiedTimestamp', 'MaximumMessageSize', 'MessageRetentionPeriod', 'Policy', 'QueueArn', 'ReceiveMessageWaitTimeSeconds', 'RedriveAllowPolicy', 'RedrivePolicy', 'SqsManagedSseEnabled', 'VisibilityTimeout']"
[list-item]
AttributeNames=["ApproximateReceiveCount", "SentTimestamp"],
^
Found 2 errors in 1 file (checked 1 source file)
Expected output
Success: no issues found in 1 source files
Thank you for the report! Looks like an error in botocore shapes, because it says AttributeNames: List[QueueAttributeName]. However, boto3 documentation looks correct. Let me check if boto3 somehow overrides the value.
I will add a stub for this parameter.
botocore bug report: https://github.com/boto/botocore/issues/2726
Fixed in mypy-boto3-sqs 1.24.40. Please let me know if it works as it should.
Please let me know if it works as it should.
I think this is still not quite right as I now have the inverse problem:
xxx.py:154: error: List item 0 has incompatible type "Literal['ApproximateNumberOfMessages']"; expected
"Literal['AWSTraceHeader', 'All', 'ApproximateFirstReceiveTimestamp', 'ApproximateReceiveCount', 'MessageDeduplicationId', 'MessageGroupId', 'SenderId', 'SentTimestamp', 'SequenceNumber', 'SqsManagedSseEnabled']"
As mentioned in my original report, I think that AttributeNames should be Sequence[MessageSystemAttributeNameType | QueueAttributeNameType] instead of Sequence[QueueAttributeNameType], but 5cd024419b6867a1bda90122f12a56c1f45b38cb changed this to Sequence[QueueAttributeFilterType] where QueueAttributeFilterType is newly added as QueueAttributeNameType | Literal['All', 'SqsManagedSseEnabled']
As of 1.24.40 I'm seeing the following in mypy_boto3_sqs/literals.py:
...
MessageSystemAttributeNameType = Literal[
"AWSTraceHeader",
"ApproximateFirstReceiveTimestamp",
"ApproximateReceiveCount",
"MessageDeduplicationId",
"MessageGroupId",
"SenderId",
"SentTimestamp",
"SequenceNumber",
]
QueueAttributeFilterType = Literal[
"AWSTraceHeader",
"All",
"ApproximateFirstReceiveTimestamp",
"ApproximateReceiveCount",
"MessageDeduplicationId",
"MessageGroupId",
"SenderId",
"SentTimestamp",
"SequenceNumber",
"SqsManagedSseEnabled",
]
QueueAttributeNameType = Literal[
"All",
"ApproximateNumberOfMessages",
"ApproximateNumberOfMessagesDelayed",
"ApproximateNumberOfMessagesNotVisible",
"ContentBasedDeduplication",
"CreatedTimestamp",
"DeduplicationScope",
"DelaySeconds",
"FifoQueue",
"FifoThroughputLimit",
"KmsDataKeyReusePeriodSeconds",
"KmsMasterKeyId",
"LastModifiedTimestamp",
"MaximumMessageSize",
"MessageRetentionPeriod",
"Policy",
"QueueArn",
"ReceiveMessageWaitTimeSeconds",
"RedriveAllowPolicy",
"RedrivePolicy",
"SqsManagedSseEnabled",
"VisibilityTimeout",
]
...
Amazon's documentation is broken/confusing, but I think this should be both sets of attributes combined, effectively:
QueueAttributeFilterType = Literal[
"AWSTraceHeader",
"All",
"ApproximateFirstReceiveTimestamp",
"ApproximateNumberOfMessages",
"ApproximateNumberOfMessagesDelayed",
"ApproximateNumberOfMessagesNotVisible",
"ApproximateReceiveCount",
"ContentBasedDeduplication",
"CreatedTimestamp",
"DeduplicationScope",
"DelaySeconds",
"FifoQueue",
"FifoThroughputLimit",
"KmsDataKeyReusePeriodSeconds",
"KmsMasterKeyId",
"LastModifiedTimestamp",
"MaximumMessageSize",
"MessageDeduplicationId",
"MessageGroupId",
"MessageRetentionPeriod",
"Policy",
"QueueArn",
"ReceiveMessageWaitTimeSeconds",
"RedriveAllowPolicy",
"RedrivePolicy",
"SenderId",
"SentTimestamp",
"SequenceNumber",
"SqsManagedSseEnabled",
"VisibilityTimeout",
]
Looks like values from QueueAttributeNameType do not have any effect. However, Let's wait for a proper fix from AWS team. I left only values listed in boto3 documentation.
https://github.com/aws/aws-sdk/issues/310
@ngnpope if you have time, could you please test on your code and send me a list of correct values? is it really Union[MessageSystemAttributeNameType,QueueAttributeNameType]?
FInally fixed in mypy-boto3-sqs1.24.60.