1
2
Fork
You've already forked boncord
1

The allow key in discord's override object is a string #1

Merged
EmmaTech merged 1 commit from goldy/boncord:main into main 2025年04月15日 00:08:24 +02:00
Contributor
Copy link

The Override discord object returns a string for the allow key instead of an integer so get_enum_from_payload fails to convert values there to the PermissionFlags enum on line 100 of models/channel.py:

allow = get_enum_from_payload(payload, PermissionFlags, "allow", required=True)
deny = get_enum_from_payload(payload, PermissionFlags, "deny", required=True)

Raising such an error:

truncated...
 File "/home/goldy/Documents/projects/goldy/python/.testing/boncord-testing/main.py", line 28, in main
 channel = await TextChannel.fetch(bot, 863416694092333080)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 391, in fetch
 return cls.from_payload(bot, payload)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 354, in from_payload
 overwrites = [Overwrite.from_payload(o) for o in payload["permission_overwrites"]]
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 354, in <listcomp>
 overwrites = [Overwrite.from_payload(o) for o in payload["permission_overwrites"]]
 ^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 100, in from_payload
 allow = get_enum_from_payload(payload, PermissionFlags, "allow", required=True)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/internal/payload.py", line 47, in get_enum_from_payload
 return enum_(obj)
 ^^^^^^^^^^
 File "/usr/lib/python3.11/enum.py", line 714, in __call__
 return cls.__new__(cls, value)
 ^^^^^^^^^^^^^^^^^^^^^^^
 File "/usr/lib/python3.11/enum.py", line 1145, in __new__
 raise exc
 File "/usr/lib/python3.11/enum.py", line 1122, in __new__
 result = cls._missing_(value)
 ^^^^^^^^^^^^^^^^^^^^
 File "/usr/lib/python3.11/enum.py", line 1385, in _missing_
 raise ValueError(
ValueError: '2147552256' is not a valid PermissionFlags

This pr fixes this by casting the value to an int if the enum inherits from enum.IntFlag. We could possibly add onto this in the future for other types.

The [Override](https://discord.com/developers/docs/resources/channel#overwrite-object) discord object returns a string for the `allow` key instead of an integer so `get_enum_from_payload` fails to convert values there to the `PermissionFlags` enum on line 100 of [models/channel.py](https://codeberg.org/EmmaTech/boncord/src/commit/5b0661d1bb13d7945d23dcfdedd08b362e6ed35c/src/boncord/models/channel.py#L100-L101): https://codeberg.org/EmmaTech/boncord/src/commit/5b0661d1bb13d7945d23dcfdedd08b362e6ed35c/src/boncord/models/channel.py#L100-L101 Raising such an error: ``` truncated... File "/home/goldy/Documents/projects/goldy/python/.testing/boncord-testing/main.py", line 28, in main channel = await TextChannel.fetch(bot, 863416694092333080) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 391, in fetch return cls.from_payload(bot, payload) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 354, in from_payload overwrites = [Overwrite.from_payload(o) for o in payload["permission_overwrites"]] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 354, in <listcomp> overwrites = [Overwrite.from_payload(o) for o in payload["permission_overwrites"]] ^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/models/channel.py", line 100, in from_payload allow = get_enum_from_payload(payload, PermissionFlags, "allow", required=True) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/goldy/Documents/projects/goldy/python/goldy-boncord/src/boncord/internal/payload.py", line 47, in get_enum_from_payload return enum_(obj) ^^^^^^^^^^ File "/usr/lib/python3.11/enum.py", line 714, in __call__ return cls.__new__(cls, value) ^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/enum.py", line 1145, in __new__ raise exc File "/usr/lib/python3.11/enum.py", line 1122, in __new__ result = cls._missing_(value) ^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/enum.py", line 1385, in _missing_ raise ValueError( ValueError: '2147552256' is not a valid PermissionFlags ``` This pr fixes this by casting the value to an int if the enum inherits from `enum.IntFlag`. We could possibly add onto this in the future for other types.
EmmaTech left a comment
Copy link

yea I should've accounted for this in the first place :p
guess I forgot it can be in string form
thankie!!!

yea I should've accounted for this in the first place :p guess I forgot it can be in string form thankie!!!
Sign in to join this conversation.
No reviewers
Labels
Clear labels
Compat/Breaking
Breaking change that won't be backward compatible
Kind/Bug
Something is not working
Kind/Documentation
Documentation changes
Kind/Enhancement
Improve existing functionality
Kind/Feature
New functionality
Kind/Security
This is security issue
Kind/Testing
Issue or pull request related to testing
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
EmmaTech/boncord!1
Reference in a new issue
EmmaTech/boncord
No description provided.
Delete branch "goldy/boncord:main"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?