Skip to content

Commit c89be8c

Browse files
cuducosauvipy
andauthored
fix: default value for SQS's receive message (#2405)
* fix: default value for SQS's receive message After #2300, `MessageAttributeNames` and `MessageSystemAttributeNames` had `None` as default values, but `None` is not a valid value for those fields. See: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/sqs/client/receive_message.html This commit suggests adding `[]` as the new default value for those fields following the error message below and the docs above. Closes #2403 * Adds test to SQS's MessageAttributeNames and MessageSystemAttributeNames * Fixes tests * Removes `None` as mock's default --------- Co-authored-by: Asif Saif Uddin {"Auvi":"অভি"} <auvipy@gmail.com>
1 parent ecbb733 commit c89be8c

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

kombu/transport/SQS.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,9 +545,10 @@ def _receive_message(
545545
client = self.sqs(queue=queue)
546546

547547
message_system_attribute_names = self.get_message_attributes.get(
548-
'MessageSystemAttributeNames')
548+
'MessageSystemAttributeNames') or []
549+
549550
message_attribute_names = self.get_message_attributes.get(
550-
'MessageAttributeNames')
551+
'MessageAttributeNames') or []
551552

552553
params: dict[str, Any] = {
553554
'QueueUrl': q_url,
@@ -964,7 +965,7 @@ def get_message_attributes(self) -> dict[str, Any]:
964965

965966
if fetch is None or isinstance(fetch, str):
966967
return {
967-
'MessageAttributeNames': None,
968+
'MessageAttributeNames': [],
968969
'MessageSystemAttributeNames': [APPROXIMATE_RECEIVE_COUNT],
969970
}
970971

@@ -988,7 +989,7 @@ def get_message_attributes(self) -> dict[str, Any]:
988989
)
989990

990991
return {
991-
'MessageAttributeNames': sorted(message_attrs) if message_attrs else None,
992+
'MessageAttributeNames': sorted(message_attrs) if message_attrs else [],
992993
'MessageSystemAttributeNames': (
993994
sorted(message_system_attrs) if message_system_attrs else [APPROXIMATE_RECEIVE_COUNT]
994995
)

t/unit/transport/test_SQS.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ def receive_message(
125125
QueueUrl=None,
126126
MaxNumberOfMessages=1,
127127
WaitTimeSeconds=10,
128-
MessageAttributeNames=None,
129-
MessageSystemAttributeNames=None
128+
MessageAttributeNames=[],
129+
MessageSystemAttributeNames=[],
130130
):
131+
assert isinstance(MessageAttributeNames, (list, tuple))
132+
assert isinstance(MessageSystemAttributeNames, (list, tuple))
131133
self._receive_messages_calls += 1
132134
for q in self._queues.values():
133135
if q.url == QueueUrl:

0 commit comments

Comments
 (0)