Code

#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.

Attachments (0)

Change History (2)

comment:1 Changed 16 months ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 16 months ago by carljm

  • Resolution set to worksforme
  • Status changed from new to closed

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.)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.