Skip to content

Conversation

@DA-344
Copy link
Contributor

@DA-344 DA-344 commented Oct 22, 2025

Summary

Contained items (in Containers, ActionRows, etc.) had some attributes outdated or uncorrectly set as another value. This PR attempts to fix it.

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, ...)

Copy link
Contributor

@laggron42 laggron42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the patch!

I have been writing test cases on my end to help covering the weird situations, and I'm still failing on your branch checking for ActionRow.parent which should be Container but is None (same example as the issue).
I also noticed that button.parent and self inside the button callback are of the same type (ActionRow), but not the same instance. It's probably due to all the deepcopy going on, I don't know how problematic that actually is.

My bad, my venv was not properly configured and did not use the right code 😓 The only case failing is self.parent.parent being None instead of Layout

Download this file, drop it in the tests folder, and run it with pytest -k test_ui_nested. I think it's worth pushing the test along the PR to avoid regression.

test_ui_nested.py

Comment on lines 133 to 135
for child in children:
self.add_item(child)
self._weight: int = sum(i.width for i in self._children)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_item fails because it needs self._weight to exist

Suggested change
for child in children:
self.add_item(child)
self._weight: int = sum(i.width for i in self._children)
self._weight: int = sum(i.width for i in self._children)
for child in children:
self.add_item(child)

@DA-344
Copy link
Contributor Author

DA-344 commented Oct 22, 2025

A view will never be a parent, that is why parent is set to None when it is at layout level (and the reason why view exists).

@laggron42
Copy link
Contributor

Oooh, that makes sense alright! Then all of my tests pass

Copy link
Owner

@Rapptz Rapptz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how I feel about this fix honestly. It's not incorrect but it does feel a bit messy since there are now multiple places where the callback binding needs to be handled. I'm not a fan of that right now though I guess a better approach can be figured out later.

As proof of how finicky this stuff is to deal with now, you forgot to do this to Select components.

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

3 participants