#31683: Overridden methods ignored in models.DecimalField subclass
-------------------------------------+-------------------------------------
Reporter: | Owner: nobody
maxrothman |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Release | Keywords: custom-model-fields
blocker |
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Django: 2.2.4
Python: 3.6.9
Mysql: 5.6.47
It appears to be impossible to override any methods in subclasses of
{{{models.DecimalField}}} under certain circumstances. Consider the
following:
{{{#!python
class Field1(models.DecimalField):
def get_prep_value(self, value):
1/0
class Field2(models.PositiveIntegerField):
def get_prep_value(self, value):
1/0
class TestModel1(models.Model):
m = Field1(max_digits=5, decimal_places=2)
class TestModel2(models.Model):
m = Field2()
TestModel1(m=1).save() # No error!
TestModel2(m=1).save() # Error, as expected
}}}
I'd expect to get an error when saving {{{TestModel1}}} because
get_prep_value should throw a {{{ZeroDivisionError}}}, but as far as I can
tell, {{{Field1.get_prep_value}}} is never called.
This bug appears to be somewhat sensitive to platform conditions. I've
been able to replicate it consistently on my machine, but another one of
my colleagues who tried was not.
--
Ticket URL: <https://code.djangoproject.com/ticket/31683>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.4cf7c90a666d05636b6a7656fc4f0039%40djangoproject.com.