﻿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
27476	model Integer fields (and derivatives) do not raise a ValidationError while other types do	Romeo Mihalcea	nobody	"I have a model with `Decimal` fields, `Boolean` fields and some `Integer` fields. While testing with invalid data (I mostly supplied a string to these fields) I noticed that the integer fields do not raise a `ValidationError` while all of the other fields do so. Supplying a string to all Integer fields raise a `ValueError` instead which looks like all other fields have a basic validation in place while the Integers do not. I know I'm supposed to perform the validations before the data reaches the model but this is testing and I like to make sure everything is as intended.

Example:


{{{
# model
class Worker(models.Model):
    ...
    disabled = models.BooleanField(default=False)
    max_execution = models.PositiveSmallIntegerField(default=3600, null=False)


# testcase
class TestModelWorker(unittest.TestCase):

    def test_max_execution(self):
        # Here we expect a Python ValueError to be raised when providing a string
        # as an argument to what is a `PositiveSmallIntegerField` 
        with self.assertRaises(ValueError) as e:
            Worker.create(
                name=""Worker"",
                max_execution='s'
            )

        self.assertIn('invalid literal for int() with base 10', str(e.exception))

    def test_disabled(self):
        # While here we can expect a `ValidationError` when providing a string to a `BooleanField`
        with self.assertRaises(ValidationError) as e:
            Worker.create(
                name=""Worker"",
                disabled='s'
            )
}}}

"	Bug	new	Database layer (models, ORM)	1.10	Normal		models, integer, ValidationError		Unreviewed	0	0	0	0	0	0
