Skip to content

Commit 23a695b

Browse files
authored
fix: don't pass kwargs to modal callbacks that only have ctx (#1619)
Fixes #1517. Supercedes #1584.
1 parent f2becee commit 23a695b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

interactions/client/client.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,17 @@ def add_modal_callback(self, command: ModalCommand) -> None:
13531353
command: The command to add
13541354
13551355
"""
1356+
# test for parameters that arent the ctx (or self)
1357+
if command.has_binding:
1358+
callback = functools.partial(command.callback, None, None)
1359+
else:
1360+
callback = functools.partial(command.callback, None)
1361+
1362+
if not inspect.signature(callback).parameters:
1363+
# if there are none, notify the command to just pass the ctx and not kwargs
1364+
# TODO: just make modal callbacks not pass kwargs at all (breaking)
1365+
command._just_ctx = True
1366+
13561367
for listener in command.listeners:
13571368
if isinstance(listener, re.Pattern):
13581369
if listener in self._regex_component_callbacks.keys():

interactions/models/internal/application_commands.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,13 @@ class ComponentCommand(InteractionCommand):
845845

846846

847847
@attrs.define(eq=False, order=False, hash=False, kw_only=True)
848-
class ModalCommand(ComponentCommand): ...
848+
class ModalCommand(ComponentCommand):
849+
_just_ctx: bool = attrs.field(repr=False, default=False)
850+
851+
async def call_callback(self, callback: Callable, context: "BaseContext") -> None:
852+
if self._just_ctx:
853+
return await self.call_with_binding(callback, context)
854+
return await super().call_callback(callback, context)
849855

850856

851857
def _unpack_helper(iterable: typing.Iterable[str]) -> list[str]:

0 commit comments

Comments
 (0)