Opened 4 years ago

Closed 4 years ago

#32582 closed Cleanup/optimization (fixed)

Extra dot in cloned test database file names on SQLite when using --parallel.

Reported by: Christian Abbott Owned by: Girish Sontakke
Component: Testing framework Version: 3.1
Severity: Normal Keywords: sqlite test clone database parallel
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

When asking Django to create on-disk (instead of in-memory) sqlite cloned test databases by using the --parallel flag, the cloned file names are created as, e.g., "test_db_1..sqlite3", "test_db_2..sqlite3", etc. (with two dots instead of one).

If the specified test database name lacks any extension, e.g. just 'test_db', then the cloned file names have a trailing dot: "test_db_1.", "test_db_2.", "test_db_3.", etc.

This is due to this line:

https://github.com/django/django/blob/main/django/db/backends/sqlite3/creation.py#L58

...in get_test_db_clone_settings() which constructs the file name using the string:

'{}_{}.{}'.format(root, suffix, ext)

However, os.path.splitext() already includes the dot in the returned extension ('ext'). Removing the dot from the format string seems the only change needed to fix it:

'{}_{}{}'.format(root, suffix, ext)

From the github file history it looks like this quirk has been there since the --parallel flag was first introduced (commit 0586c061f0b857e2259bea48e21ebb69a7878d13 in Sep 2015).

To reproduce the issue:

In settings.py, force on-disk instead of in-memory test databases by specifying any test db name:

DATABASES = {
    'default': {
        ENGINE: 'django.db.backends.sqlite3',
        NAME: 'db.sqlite3',
        TEST: {
            'NAME': test_db.sqlite3',
        }
    }
}

Create any model with migrations, and more than one TestCase class (to ensure --parallel creates clones of the test database).

And on the command line, run tests with --parallel and --keepdb to see the db files generated. This should be run on a multi-core processor.

manage.py test --parallel --keepdb

Change History (7)

comment:1 by Mariusz Felisiak, 4 years ago

Summary: Extra dot between file name and extension on sqlite cloned test databases when using --parallel flagExtra dot in cloned test database file names on SQLite when using --parallel.
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Good catch, would you like to prepare a patch? (tests are required)

in reply to:  1 comment:2 by Girish Sontakke, 4 years ago

Replying to Mariusz Felisiak:

Good catch, would you like to prepare a patch? (tests are required)

May I work on this patch.

comment:3 by Girish Sontakke, 4 years ago

Owner: changed from nobody to Girish Sontakke
Status: newassigned

comment:5 by Mariusz Felisiak, 4 years ago

Has patch: set
Needs tests: set

comment:6 by Mariusz Felisiak, 4 years ago

Needs tests: unset
Triage Stage: AcceptedReady for checkin

comment:7 by GitHub <noreply@…>, 4 years ago

Resolution: fixed
Status: assignedclosed

In 5388ff2a:

Fixed #32582 -- Removed unnecessary dot in names of cloned test databases on SQLite.

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