#27825: ORM Object constructor does not cast types of it's attributes when
called
by reference
---------------------------------------------+------------------------
Reporter: Oleg Belousov | Owner: nobody
Type: Bug | Status: new
Component: Testing framework | Version: 1.10
Severity: Normal | Keywords: ORM
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
---------------------------------------------+------------------------
My experience is that when using the `Constructor` (`ORM`) class by
references with Django `1.10.5`
There might be some inconsistencies in the data (i.e. the attributes of
the created object may get the type of the input data instead of the
casted type of the ORM object property)
Example:
`models`
{{{
class Payment(models.Model):
amount_cash = models.DecimalField()
}}}
`some_test.py` - `object.create`
{{{
Class SomeTestCase:
def generate_orm_obj(self, _constructor, base_data=None,
modifiers=None):
objs = []
if not base_data:
base_data = {'amount_case': 123.00}
for modifier in modifiers:
actual_data = deepcopy(base_data)
actual_data.update(modifier)
_obj = _constructor.objects.create(**actual_data)
print(type(_obj.amount_cash)) # Decimal
return objs
}}}
`some_test.py` - `Constructor()`
{{{
Class SomeTestCase:
def generate_orm_obj(self, _constructor, base_data=None,
modifiers=None):
objs = []
if not base_data:
base_data = {'amount_case': 123.00}
for modifier in modifiers:
actual_data = deepcopy(base_data)
actual_data.update(modifier)
_obj = _constructor(**actual_data)
print(type(_obj.amount_cash)) # Float
objs.append(_obj) return objs
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/27825>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.15e78107ccfd323fdd0d67bf70fdfa94%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.