Skip to content

fix: don't pass kwargs to modal callbacks that only have ctx #1619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,17 @@ def add_modal_callback(self, command: ModalCommand) -> None:
command: The command to add

"""
# test for parameters that arent the ctx (or self)
if command.has_binding:
callback = functools.partial(command.callback, None, None)
else:
callback = functools.partial(command.callback, None)

if not inspect.signature(callback).parameters:
# if there are none, notify the command to just pass the ctx and not kwargs
# TODO: just make modal callbacks not pass kwargs at all (breaking)
command._just_ctx = True

for listener in command.listeners:
if isinstance(listener, re.Pattern):
if listener in self._regex_component_callbacks.keys():
Expand Down
8 changes: 7 additions & 1 deletion interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,13 @@ class ComponentCommand(InteractionCommand):


@attrs.define(eq=False, order=False, hash=False, kw_only=True)
class ModalCommand(ComponentCommand): ...
class ModalCommand(ComponentCommand):
_just_ctx: bool = attrs.field(repr=False, default=False)

async def call_callback(self, callback: Callable, context: "BaseContext") -> None:
if self._just_ctx:
return await self.call_with_binding(callback, context)
return await super().call_callback(callback, context)


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