#15691 closed Bug (worksforme)
TEST_DEPENDENCIES doesn't use TEST_NAME in circular dependency detection.
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Testing framework | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
As far as I can tell, TEST_DEPENDENCIES checks for circular dependencies by looking at the NAME key, ignoring TEST_NAME if it exists.
This means that if you have some aliases that use the same NAME but different TEST_NAMEs, it will bail out reporting a circular dependency even though there isn't one. Example:
DATABASES = { 'default': { 'NAME': 'mydb', ... 'TEST_NAME': 'test_mydb', 'TEST_DEPENDENCIES': ['users'], }, 'users': { 'NAME': 'mydb', ... 'TEST_NAME': 'test_users', 'TEST_DEPENDENCIES': [], },
It's reasonable to ask why you'd have multiple database configs with the same NAME. On OpenBlock we've been doing that as our default setup, because most of our dev rigs and deployments use only one physical database, but when running tests we want to be sure that multi-database setups work.
Attachments (2)
Change History (11)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
Type: | → Bug |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|
comment:4 by , 14 years ago
milestone: | → 1.4 |
---|---|
Triage Stage: | Unreviewed → Accepted |
follow-up: 6 comment:5 by , 13 years ago
Easy pickings: | unset |
---|---|
Has patch: | set |
UI/UX: | unset |
test_db_signature in db/backends/[oracle/]creation.py was not using TEST_NAME. Diff attached that gives precedence to TEST_NAME, then NAME
comment:6 by , 13 years ago
Replying to anonymous:
test_db_signature in db/backends/[oracle/]creation.py was not using TEST_NAME. Diff attached that gives precedence to TEST_NAME, then NAME
Forgot to sign my name.
comment:9 by , 3 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
This doesn't reproduce for me on latest main
.
These settings:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', 'TEST': { 'NAME': BASE_DIR / 'test_mydb', 'DEPENDENCIES': ['users'], }, }, 'users': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3', 'TEST': { 'NAME': BASE_DIR / 'test_users', 'DEPENDENCIES': [], }, }, }
This model:
from django.db import models class DefaultModel(models.Model): name = models.TextField()
This test:
from django.test import TestCase from .models import DefaultModel class TheTests(TestCase): databases = '__all__' def test_basics(self): o = DefaultModel(name="Default") o.save() o = DefaultModel(name="Users") o.save(using="users") d = DefaultModel.objects.get() u = DefaultModel.objects.using('users').get() self.assertEqual(d, u) self.assertNotEqual(d.name, u.name)
All runs without error.
I'll upload the project zip in case someone wants to play with it.
...checks for circular dependencies by looking at the NAME key, ignoring TEST_NAME if it exists...
This doesn't look right, at least how the code is now. The check compares aliases, not NAME
or TEST['NAME']
.
I'll close as worksforme
but happy to re-open if someone can provide a reproduce.
fwiw, our config hasn't caused any problems to date on Django 1.2.3. I noticed this problem because tests started failing if we tried upgrading to 1.2.4 or 1.2.5, and I traced it to the addition of TEST_DEPENDENCIES.