Skip to content

Commit ba3da41

Browse files
authored
Fix SQS CreateQueue type error by casting attributes to string (#65649)
1 parent 2d4eb59 commit ba3da41

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

  • providers/amazon

providers/amazon/src/airflow/providers/amazon/aws/hooks/sqs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ def create_queue(self, queue_name: str, attributes: dict | None = None) -> dict:
5252
:return: dict with the information about the queue.
5353
"""
5454
self.log.debug("Creating SQS queue %s with attributes %s", queue_name, attributes)
55-
result = self.get_conn().create_queue(QueueName=queue_name, Attributes=attributes or {})
55+
safe_attributes = {k: str(v) for k, v in (attributes or {}).items()}
56+
result = self.get_conn().create_queue(QueueName=queue_name, Attributes=safe_attributes or {})
5657
self.log.debug("Created SQS queue %s, response: %s", queue_name, result.get("QueueUrl"))
5758
return result
5859

providers/amazon/tests/unit/amazon/aws/hooks/test_sqs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,29 @@ def test_send_message_with_delay(self, hook):
145145
immediate_receive = hook.get_conn().receive_message(QueueUrl=self.queue_url, WaitTimeSeconds=0)
146146
assert "Messages" not in immediate_receive or len(immediate_receive.get("Messages", [])) == 0
147147

148+
def test_create_queue_with_int_attributes(self, hook):
149+
"""Test that int attribute values are internally cast to strings and queue creation succeeds."""
150+
queue_name = "test-queue-int-casting"
151+
# These are the int values that the casting logic (fixed in SqsHook) should handle.
152+
attributes = {
153+
"DelaySeconds": 10,
154+
"MaximumMessageSize": 262144,
155+
}
156+
157+
response = hook.create_queue(queue_name=queue_name, attributes=attributes)
158+
159+
assert "QueueUrl" in response
160+
assert queue_name in response["QueueUrl"]
161+
162+
# Verify that the attributes were correctly cast and stored as strings in the SQS service (moto).
163+
queue_attrs = hook.get_conn().get_queue_attributes(
164+
QueueUrl=response["QueueUrl"], AttributeNames=["DelaySeconds", "MaximumMessageSize"]
165+
)
166+
167+
# moto/boto3 returns values as strings; if these assertions pass, the casting logic is verified.
168+
assert queue_attrs["Attributes"]["DelaySeconds"] == "10"
169+
assert queue_attrs["Attributes"]["MaximumMessageSize"] == "262144"
170+
148171

149172
@pytest.mark.asyncio
150173
class TestAsyncSqsHook:

0 commit comments

Comments
 (0)