Skip to content

Commit be45708

Browse files
authored
Merge branch 'main' into resolve-conflict
2 parents abe4acd + c89be8c commit be45708

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

kombu/asynchronous/hub.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ def close(self, *args):
274274
for item in todos:
275275
item()
276276

277+
# Clear global event loop variable if this hub is the current loop
278+
if _current_loop is self:
279+
set_event_loop(None)
280+
277281
def _discard(self, fd):
278282
fd = fileno(fd)
279283
self.readers.pop(fd, None)

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/asynchronous/test_hub.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,3 +586,30 @@ def test__pop_ready_uses_lock(self):
586586
with patch.object(self.hub, '_ready_lock', autospec=True) as lock:
587587
self.hub._pop_ready()
588588
lock.__enter__.assert_called_once()
589+
590+
def test_close_clears_global_event_loop(self):
591+
# Test that closing a hub clears the global event loop if it's the current one
592+
prev_loop = get_event_loop()
593+
try:
594+
hub = Hub()
595+
set_event_loop(hub)
596+
assert get_event_loop() is hub
597+
hub.close()
598+
assert get_event_loop() is None
599+
finally:
600+
set_event_loop(prev_loop)
601+
602+
def test_close_does_not_clear_other_event_loop(self):
603+
# Test that closing a hub doesn't clear the global event loop if it's a different one
604+
prev_loop = get_event_loop()
605+
try:
606+
hub1 = Hub()
607+
hub2 = Hub()
608+
set_event_loop(hub1)
609+
assert get_event_loop() is hub1
610+
hub2.close()
611+
# hub1 should still be the current loop
612+
assert get_event_loop() is hub1
613+
hub1.close()
614+
finally:
615+
set_event_loop(prev_loop)

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)