Skip to content

Commit 86faa33

Browse files
authored
Fix #1056 by changing the default type for Option values (#1097)
1 parent 66dfc54 commit 86faa33

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

slack_sdk/models/blocks/basic_components.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ def __init__(
193193
dialogs.
194194
"""
195195
if text:
196-
self._text: Optional[TextObject] = TextObject.parse(text)
196+
# For better compatibility with Block Kit ("mrkdwn" does not work for it),
197+
# we've changed the default text object type to plain_text since version 3.10.0
198+
self._text: Optional[TextObject] = TextObject.parse(
199+
text=text, # "text" here can be either a str or a TextObject
200+
default_type=PlainTextObject.type,
201+
)
197202
self._label: Optional[str] = None
198203
else:
199204
self._text: Optional[TextObject] = None
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import unittest
2+
3+
from slack_sdk.models.blocks import (
4+
StaticSelectElement,
5+
Option,
6+
)
7+
8+
9+
class TestOptions(unittest.TestCase):
10+
def test_with_static_select_element(self):
11+
self.maxDiff = None
12+
13+
elem = StaticSelectElement(
14+
action_id="action-id",
15+
initial_option=Option(value="option-1", text="Option 1"),
16+
options=[
17+
Option(value="option-1", text="Option 1"),
18+
Option(value="option-2", text="Option 2"),
19+
Option(value="option-3", text="Option 3"),
20+
],
21+
)
22+
expected = {
23+
"action_id": "action-id",
24+
"initial_option": {
25+
"text": {"emoji": True, "text": "Option 1", "type": "plain_text"},
26+
"value": "option-1",
27+
},
28+
"options": [
29+
{
30+
"text": {"emoji": True, "text": "Option 1", "type": "plain_text"},
31+
"value": "option-1",
32+
},
33+
{
34+
"text": {"emoji": True, "text": "Option 2", "type": "plain_text"},
35+
"value": "option-2",
36+
},
37+
{
38+
"text": {"emoji": True, "text": "Option 3", "type": "plain_text"},
39+
"value": "option-3",
40+
},
41+
],
42+
"type": "static_select",
43+
}
44+
self.assertDictEqual(expected, elem.to_dict())

0 commit comments

Comments
 (0)