File tree Expand file tree Collapse file tree 4 files changed +31
-2
lines changed
Expand file tree Collapse file tree 4 files changed +31
-2
lines changed Original file line number Diff line number Diff line change 11from typing import Optional , Union , Dict , Sequence
22
33from slack_bolt .context .say .internals import _can_say
4+ from slack_bolt .util .utils import create_copy
45from slack_sdk .models .attachments import Attachment
56from slack_sdk .models .blocks import Block
67from slack_sdk .web .async_client import AsyncWebClient
@@ -45,7 +46,7 @@ async def __call__(
4546 ** kwargs ,
4647 )
4748 elif isinstance (text_or_whole_response , dict ):
48- message : dict = text_or_whole_response
49+ message : dict = create_copy ( text_or_whole_response )
4950 if "channel" not in message :
5051 message ["channel" ] = channel or self .channel
5152 return await self .client .chat_postMessage (** message )
Original file line number Diff line number Diff line change 66from slack_sdk .web import SlackResponse
77
88from slack_bolt .context .say .internals import _can_say
9+ from slack_bolt .util .utils import create_copy
910
1011
1112class Say :
@@ -46,7 +47,7 @@ def __call__(
4647 ** kwargs ,
4748 )
4849 elif isinstance (text_or_whole_response , dict ):
49- message : dict = text_or_whole_response
50+ message : dict = create_copy ( text_or_whole_response )
5051 if "channel" not in message :
5152 message ["channel" ] = channel or self .channel
5253 return self .client .chat_postMessage (** message )
Original file line number Diff line number Diff line change @@ -43,3 +43,16 @@ def test_say_invalid(self):
4343 say = Say (client = self .web_client , channel = "C111" )
4444 with pytest .raises (ValueError ):
4545 say ([])
46+
47+ def test_say_shared_dict_as_arg (self ):
48+ # this shared dict object must not be modified by say method
49+ shared_template_dict = {"text" : "Hi there!" }
50+ say = Say (client = self .web_client , channel = "C111" )
51+ response : SlackResponse = say (shared_template_dict )
52+ assert response .status_code == 200
53+ assert shared_template_dict .get ("channel" ) is None
54+
55+ say = Say (client = self .web_client , channel = "C222" )
56+ response : SlackResponse = say (shared_template_dict )
57+ assert response .status_code == 200
58+ assert shared_template_dict .get ("channel" ) is None
Original file line number Diff line number Diff line change @@ -53,3 +53,17 @@ async def test_say_invalid(self):
5353 say = AsyncSay (client = self .web_client , channel = "C111" )
5454 with pytest .raises (ValueError ):
5555 await say ([])
56+
57+ @pytest .mark .asyncio
58+ async def test_say_shared_dict_as_arg (self ):
59+ # this shared dict object must not be modified by say method
60+ shared_template_dict = {"text" : "Hi there!" }
61+ say = AsyncSay (client = self .web_client , channel = "C111" )
62+ response : AsyncSlackResponse = await say (shared_template_dict )
63+ assert response .status_code == 200
64+ assert shared_template_dict .get ("channel" ) is None
65+
66+ say = AsyncSay (client = self .web_client , channel = "C222" )
67+ response : AsyncSlackResponse = await say (shared_template_dict )
68+ assert response .status_code == 200
69+ assert shared_template_dict .get ("channel" ) is None
You can’t perform that action at this time.
0 commit comments