Opened 11 years ago

Closed 11 years ago

#20155 closed Uncategorized (worksforme)

Django doesn't appear to actually follow Database naming rules

Reported by: anonymous Owned by: nobody
Component: Testing framework Version: 1.5
Severity: Normal Keywords: TEST_NAME database
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When specifying the following, it appears django doesn't actually use the specified database:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'deathstar',
        'USER': 'root',
        'PASSWORD': 'root',
        'TEST_NAME': 'deathstar_celery',
    }
}

in a test I run:

User.objects.create_user(username='a', password='p')
import pdb; pdb.set_trace()

and in the database 'deathstar_celery' run:

select * from auth_user;

yet no results are returned.

Change History (2)

comment:1 by anonymous, 11 years ago

Sorry I should have mentioned inside django's test command. It works fine writes fine to the database if running outside of the test framework.

comment:2 by Carl Meyer, 11 years ago

Resolution: worksforme
Status: newclosed

By default every test runs inside a transaction (so as to be able to roll back the transaction at the end of the test and provide each test with a clean database state). With typical database configuration, modifications to the database within a transaction are not visible outside that transaction (i.e. from another connection) until the transaction is committed. But the test runner never commits a transaction, so you will never see the data from another connection.

(The exception is a test case that subclasses from TransactionTestCase; in this case tests are not run within a transaction in order to allow testing of transactional code.)

Note: See TracTickets for help on using tickets.
Back to Top