﻿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 17394,Models in a package breaks model validation,Wilfred Hughes ,nobody,"If I create an app: {{{ $ ./manage.py startapp test_app }}} I then create a package for my models: {{{ $ cd test_app $ mkdir models $ cd models $ touch __init__.py }}} I then create an invalid model in test_app/models/bar.py: {{{ from django.db import models class Foo(models.Model): class Meta: app_label = 'test_app.models' invalid_char_field = models.CharField() # should have max_length }}} Finally, I import this in my tests, I chose test_app/tests.py: {{{ from django.test import TestCase from models.bar import Bar class SimpleTest(TestCase): def test_basic_addition(self): """""" Tests that 1 + 1 always equals 2. """""" self.assertEqual(1 + 1, 2) }}} This has a really weird effect on model validation. Calling validate works: {{{ $ ./manage.py validate 0 errors found }}} But tests seem to have a different validation path, and fail as expected: {{{ $ ./manage.py test test_app Creating test database for alias 'default'... Error: One or more models did not validate: test_app.foo: ""invalid_char_field"": CharFields require a ""max_length"" attribute that is a positive integer. }}} I know this isn't a common use case, but I have an old project that has models like this. #2289 suggests I should be able to do this. I can work around it by adding an import for every single model in {{{test_app/models/*.py}}} inside of {{{test_app/__init__.py}}} but that introduces name clashes. Thanks. ",Uncategorized,closed,"Database layer (models, ORM)",1.3,Normal,invalid,,,Unreviewed,0,0,0,0,0,0