Skip to content

Action lookup problems on 0.63.1 #4544

@darrenburns

Description

@darrenburns

In Elia, I have a few places where you click a link and it fires an action.

My action methods are usually located at the screen level.

On the latest version (0.63.1), all of my links are broken and have lookup failures which look like this in the logs:

[21:30:52] SYSTEM                                                                  app.py:3146
<action> 'foo' has no target. Could not find methods '_action_foo' or 'action_foo'

In the latest version of Textual, I think actions are always being looked up on the App, regardless of the namespace used.

In the example app below, note that output is always The action fired on APP! - the action method on the screen never fires.

from textual import __version__
from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Label

class HomeScreen(Screen[None]):
    def compose(self) -> ComposeResult:
        yield Label(f"Textual version: {__version__}")
        yield Label("[@click=foo]Fire action (@click=foo)![/]")
        yield Label("[@click=app.foo]Fire action (@click=app.foo)![/]")
        yield Label("[@click=screen.foo]Fire action (@click=screen.foo)![/]")

    def action_foo(self) -> None:
        self.app.panic("The action fired on SCREEN!")

class ActionNamespaceBug(App[None]):
    def get_default_screen(self) -> HomeScreen:
        return HomeScreen()

    def action_foo(self) -> None:
        self.app.panic("The action fired on APP!")

if __name__ == "__main__":
    app = ActionNamespaceBug()
    app.run()

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions