Opened 5 years ago
Last modified 5 years ago
#30857 closed Bug
When subclassing a model field, `max_length` cannot be passed as an argument to `self.__init__` — at Version 1
Reported by: | Robin (Robert) Thomas | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | 2.2 |
Severity: | Normal | Keywords: | models fields |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
class MyCustomField(models.CharField): def __init__(self, *args, **kwargs): super().__init__(max_length=60, *args, **kwargs) class MyModel(models.Model) address_state = MyCustomField()
On attempting to migrate, I get:
super().__init__(max_length=60, *args, **kwargs) TypeError: __init__() got multiple values for keyword argument 'max_length'
Using kwargs[max_length]
works just fine. However, the documentation says that max_length
should be able to be passed to super().__init__()
as an argument:
https://docs.djangoproject.com/en/2.2/howto/custom-model-fields/#writing-a-field-subclass
Either the documentation is incorrect, or this is a bug.
Note:
See TracTickets
for help on using tickets.