mirror of
				https://github.com/django/django.git
				synced 2025-11-04 13:39:16 +00:00 
			
		
		
		
	Fixed #28120 -- Checked that CharField.max_length is not a boolean.
This commit is contained in:
		
							parent
							
								
									851874fe0a
								
							
						
					
					
						commit
						9f2e8b5bb7
					
				
					 3 changed files with 18 additions and 1 deletions
				
			
		
							
								
								
									
										1
									
								
								AUTHORS
									
										
									
									
									
								
							
							
						
						
									
										1
									
								
								AUTHORS
									
										
									
									
									
								
							| 
						 | 
					@ -140,6 +140,7 @@ answer newbie questions, and generally made Django that much better:
 | 
				
			||||||
    Cameron Knight (ckknight)
 | 
					    Cameron Knight (ckknight)
 | 
				
			||||||
    Can Burak Çilingir <canburak@cs.bilgi.edu.tr>
 | 
					    Can Burak Çilingir <canburak@cs.bilgi.edu.tr>
 | 
				
			||||||
    Carl Meyer <carl@oddbird.net>
 | 
					    Carl Meyer <carl@oddbird.net>
 | 
				
			||||||
 | 
					    Carles Pina i Estany <carles@pina.cat>
 | 
				
			||||||
    Carlos Eduardo de Paula <carlosedp@gmail.com>
 | 
					    Carlos Eduardo de Paula <carlosedp@gmail.com>
 | 
				
			||||||
    Carlos Matías de la Torre <cmdelatorre@gmail.com>
 | 
					    Carlos Matías de la Torre <cmdelatorre@gmail.com>
 | 
				
			||||||
    Carlton Gibson <carlton.gibson@noumenal.es>
 | 
					    Carlton Gibson <carlton.gibson@noumenal.es>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1040,7 +1040,8 @@ class CharField(Field):
 | 
				
			||||||
                    id='fields.E120',
 | 
					                    id='fields.E120',
 | 
				
			||||||
                )
 | 
					                )
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        elif not isinstance(self.max_length, int) or self.max_length <= 0:
 | 
					        elif (not isinstance(self.max_length, int) or isinstance(self.max_length, bool) or
 | 
				
			||||||
 | 
					                self.max_length <= 0):
 | 
				
			||||||
            return [
 | 
					            return [
 | 
				
			||||||
                checks.Error(
 | 
					                checks.Error(
 | 
				
			||||||
                    "'max_length' must be a positive integer.",
 | 
					                    "'max_length' must be a positive integer.",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -139,6 +139,21 @@ class CharFieldTests(TestCase):
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
        self.assertEqual(errors, expected)
 | 
					        self.assertEqual(errors, expected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def test_str_max_length_type(self):
 | 
				
			||||||
 | 
					        class Model(models.Model):
 | 
				
			||||||
 | 
					            field = models.CharField(max_length=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        field = Model._meta.get_field('field')
 | 
				
			||||||
 | 
					        errors = field.check()
 | 
				
			||||||
 | 
					        expected = [
 | 
				
			||||||
 | 
					            Error(
 | 
				
			||||||
 | 
					                "'max_length' must be a positive integer.",
 | 
				
			||||||
 | 
					                obj=field,
 | 
				
			||||||
 | 
					                id='fields.E121'
 | 
				
			||||||
 | 
					            ),
 | 
				
			||||||
 | 
					        ]
 | 
				
			||||||
 | 
					        self.assertEqual(errors, expected)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_non_iterable_choices(self):
 | 
					    def test_non_iterable_choices(self):
 | 
				
			||||||
        class Model(models.Model):
 | 
					        class Model(models.Model):
 | 
				
			||||||
            field = models.CharField(max_length=10, choices='bad')
 | 
					            field = models.CharField(max_length=10, choices='bad')
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue