Skip to content

Conversation

@laggron42
Copy link
Contributor

Summary

This PR adds checks to ensure the view and parent properties of UI components are properly set when there are multiple layers of nesting. It also checks that all interaction_check methods are called.

Resolves #10335 when the tests pass.

Test details

The test will build the following nested objects: LayoutView > Container > ActionRow > Item (Button or Select)

They are constructed in 3 ways for each test:

  • class methods and decorators
  • class constructors (Container(ActionRow(Item())))
  • add_item methods (c=Container();c.add_item(...))

Current failing test cases:

  • item.parent not set for items created via class constructors
  • item.parent returns a different instance than row but of correct type for a button created via decorator
    • item.parent.parent set to None instead of container

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@laggron42
Copy link
Contributor Author

To clear some confusion, I wrote this minimal test to demonstrate the case that is still failing. Buttons are instanciated using decorators, both inside ActionRow and Container. These methods are shown in the documentation

import asyncio
from discord.ui import *

class MyActionRow(ActionRow):
    @button()
    async def btn1(self, inter, btn):
        pass

class MyContainer(Container):
    myrow = MyActionRow()

    @myrow.button()
    async def btn2(self, inter, btn):
        pass

class MyView(LayoutView):
    container = MyContainer()

async def main():
    view = MyView()
    print(view.container.view)  # <MyView timeout=180.0 children=1>
    print(view.container.myrow.view)  # <MyView timeout=180.0 children=1>
    print(view.container.myrow.btn1.view)  # None
    print(view.container.btn2.view)  # None

asyncio.run(main())

Both button.view are None when using the decorator inside a class. It still works when using constructors or add_item.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[V2 components] Weird nesting behavior

1 participant