Skip to content
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

Adding the 26th option did not raise a ValueError on Select #9878

Closed
3 tasks done
junah201 opened this issue Jul 5, 2024 · 2 comments · Fixed by #9879
Closed
3 tasks done

Adding the 26th option did not raise a ValueError on Select #9878

junah201 opened this issue Jul 5, 2024 · 2 comments · Fixed by #9879
Labels
unconfirmed bug A bug report that needs triaging

Comments

@junah201
Copy link
Contributor

junah201 commented Jul 5, 2024

Summary

Adding the 26th option did not raise a ValueError on Select

Reproduction Steps

Following PR #9875, I was writing test code for discord.ui.Select. At that time, I recognize that adding the 26th option didn't raise a ValueError. In fact, discord.ui.Select raises a ValueError when adding the 27th option.

Minimal Reproducible Code

import discord

bot = discord.Client(
    intents=discord.Intents.all()
)


@bot.event
async def on_message(message: discord.Message):
    if message.content == "!test":
        select = discord.ui.Select()
        for i in range(1, 25 + 1):
            select.add_option(label=f"Test {i}", value=str(i))

        # add 26th option
        select.add_option(label="26", value="26")

        view = discord.ui.View()
        view.add_item(select)

        await message.channel.send("Select Test", view=view)

bot.run("token")

Expected Results

A valueError is expected to occur when the 26th option is added to the select, not when sending the view to discord.

ValueError: maximum number of options already provided

Actual Results

When I send Select with 26 options, discord.errors.HTTPException occured.

discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In components.0.components.0.options: Must be between 1 and 25 in length.

Intents

discord.Intents.all

System Information

$ python -m discord -v

  • Python v3.10.7-final
  • discord.py v2.5.0-alpha
    • discord.py metadata: v2.5.0a5058+ge5324907
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.22631

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

if len(self._underlying.options) > 25:
raise ValueError('maximum number of options already provided')

@junah201 junah201 added the unconfirmed bug A bug report that needs triaging label Jul 5, 2024
junah201 added a commit to junah201/discord.py that referenced this issue Jul 5, 2024
@MCausc78
Copy link
Contributor

MCausc78 commented Jul 5, 2024

This is Discord responsibility to validate select options length. discord.py usually will not validate this.

@junah201
Copy link
Contributor Author

junah201 commented Jul 5, 2024

@MCausc78
I understand your point, but since adding the 27th option raises a ValueError, it seems more like an unintended behavior rather than a question of responsibility. Additionally, regardless of whose responsibility it is, discord.py does appear to be performing this validation (with some bug).

children[name] = member
if len(children) > 25:
raise TypeError('View cannot have more than 25 children')
cls.__view_children_items__ = list(children.values())

if len(self._underlying.options) > 25:
raise ValueError('maximum number of options already provided')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
unconfirmed bug A bug report that needs triaging
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants