tortoise / tortoise/tortoise-orm
Python Enum.IntEnum datatype do not fit on Tortoise.fields.IntEnumField when not int16
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.6k
- Forks
- 516
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 9
Description
Describe the bug
Python Enum.IntEnum datatype do not fit on Tortoise.fields.IntEnumField when any element of enumeration is outside of int16 range.
IMHO, this should not behave like that (or at least configurable), since Python object can handle values larger than that.
To Reproduce
import enum
import tortoise.fields as fields
class PROTOCOL_ID(enum.IntEnum):
A = 10000
B = 80000
protocol_id = fields.IntEnumField(enum_type=PROTOCOL_ID)
Fails with
ConfigurationError: The valid range of IntEnumField's values is -32768..32767!
Expected behavior
I expect that I could store values larger or smaller than int16 on that. Or at least a BigintEnumField. and SmallIntEnumField.
IMHO the naming should reflect the regular Int type fields as;
- Small = 16 bits
- Default = 32bits
- Big = 64Bits
Additional context
If not possible, is there a workaround? I do not want store that protocol static data into a database to increase the query complexity.
Python 3.9.7
Tortoise 0.17.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Tortoise.fields.IntEnumField entry point and trace how it validates enum values against the int16 range. Check the related integer field behavior and tests. Done means IntEnum values outside the int16 range can be represented as requested, with coverage for the reported 10000 and 80000 values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100