-
Notifications
You must be signed in to change notification settings - Fork 112
Description
Bug description
I encountered this bug while working with the display of Spells on the FE. I notice that the "casting_time" was returning values outside of the enumerated types associated with this field (the TS types were generated directly from the Swagger spec).
Investigating, I first took a look at Spell model field for casting_time:
casting_time = models.TextField(
choices = SPELL_CASTING_TIME_CHOICES,
help_text = "Casting time key, such as 'action'")
From api_v2/models/enums.py
SPELL_CASTING_TIME_CHOICES = [
('reaction',"Reaction"),
('bonus-action',"1 Bonus Action"),
('action',"1 Action"),
('turn',"1 Turn"),
('round',"1 Round"),
('1minute',"1 Minute"),
('5minutes',"5 Minutes"),
('10minutes',"10 Minutes"),
('1hour',"1 Hour"),
('4hours',"4 Hours"),
('7hours',"7 Hours"),
('8hours',"8 Hours"),
('9hours',"9 Hours"),
('12hours',"12 Hours"),
('24hours',"24 Hours"),
('1week',"1 Week")
]
This feels like it ought to handle the validation to stop a value being assigned to casting_time that is outside of the SPELL_CASTING_TIME_CHOICES enum, but it doesn't.
[
{
"model": "api_v2.spell",
"pk": "srd-2024_healing-word",
"fields": {
"name": "Healing Word",
...
"casting_time": "bonus_action",
....
The value "bonus_action" is not a valid option in the enum, it should be "bonus-action", but Django doesn't seem to flag this as an issue when the DB is built.
Desired Behaviour
That Django validates TextFields with choice properties to ensure that only values specified in the choices enum can be assigned to the field.
Steps to Reproduce
- Fork the
stagingbranch of the Open5e API - Change the
"casting_time"of any spell to something outside of theSPELL_CASTING_TIME_CHOICES. ie. "TEST". - When we run
pipenv run python manage.py quicksetup, no validation error is thrown. DB is built as normal. - Spin up a local Django dev server (
pipenv run python manage.py runserver) and visit the endpoint for the spell you just changed. Notice that the"casting_time"has been updated to a value disallowed by theSPELL_CASTING_TIME_CHOICESenum.