﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
34057	Validation of DecimalField	Shivan Sivakumaran	nobody	"I'm using factory boy to create fixtures for my tests. I have this model:

I am using:
- django 4.1.1
- factoryboy 3.2.1
- pytest 7.1.3
- pytest-django 4.5.2
- pytest-factoryboy 2.5.0

{{{#!python
class Lift(models.Model):
    ...

    bodyweight = models.DecimalField(
        blank=True, max_digits=5, decimal_places=2
    )
}}}

Here is my factory:

{{{#!python
class LiftFactory(factory.DjagoModelFactory):
    ...
    
    @factory.lazy_attribute
    def bodyweight(self):
        return round(random.uniform(50, 150), 2)
}}}

When I run my test, I get an error:

{{{#!python
django.core.exceptions.ValidationError: {'bodyweight': ['Ensure that there are no more than 2 decimal places.']}
}}}

However, when I wrap the `random.uniform` with `Decimal`, it works!! Like so:
{{{#!python
return round(Decimal(random.uniform(50, 150), 2))
}}}

Is this a problem with how float and decimal types are dealt with? Or am I doing something wrong?

I apologise, I don't know if this is a ""mistake"" with `factoryboy` or `django`.
"	Bug	closed	Database layer (models, ORM)	4.1	Normal	invalid	decimal, float		Unreviewed	0	0	0	0	0	0
