Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#18347 closed Bug (fixed)

Unit tests contain raw inserts to an identity column

Reported by: Michael Manfre Owned by: Anssi Kääriäinen
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: identity insert, mssql
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

Two unit tests in transactions_regress.TestTransactionClosing fail for MSSQL because of raw inserts in to an identity column. MSSQL and potentially other 3rd party backends require actions to allow this type of insert.

Change History (10)

comment:1 by Michael Manfre, 13 years ago

Easy pickings: set
Has patch: set

Pull request https://github.com/manfre/django/commit/06d8aee7edc1ff2862ad8c64d1097090df46fdfa

Added enable_identity_insert, disable_identity_insert, and
contextmanager identity_insert_enabled to DatabaseOperations for
database backends that need to take special actions to allow
identity inserts.

All raw insert statements that set a value in to the identity field
should include these guards to allow all database backends to
function.

Implementation followed the paradigm used by enable/disable constraints.

comment:2 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedAccepted

The patch looks pretty good to me.

However, wouldn't it be just as easy to not include the primary key in the inserted values in these two tests? I wouldn't like to expand the database backend API more than necessary.

comment:3 by Anssi Kääriäinen, 13 years ago

An alternate patch which just removes inserts into the primary key field. Would this work for mssql? If not, then adding a new model without autofield primary key is still one possibility.

https://github.com/akaariai/django/tree/ticket_18347

comment:4 by Michael Manfre, 13 years ago

Tests pass with your patch.

comment:5 by Michael Manfre, 12 years ago

Owner: changed from Michael Manfre to Anssi Kääriäinen

Passing ownership because your patch works for django-mssql

comment:6 by Jan Bednařík, 12 years ago

Triage Stage: AcceptedReady for checkin

Patch from akaariai works, tests pass also for PostgreSQL and SQLite3 (if test is not skipped).

comment:7 by Aymeric Augustin, 12 years ago

The patch looks good to me too.

comment:8 by Anssi Kääriäinen <akaariai@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 71e14cf3aa024496adcb23e83ddf13a7c5ddeb32:

Fixed #18347 -- Removed autofield raw SQL inserts from tests

comment:9 by Anssi Kääriäinen <akaariai@…>, 12 years ago

In a1fd9555f2cc32d10cdbc4aa71f86bac50ffd9c1:

[1.5.x] Fixed #18347 -- Removed autofield raw SQL inserts from tests

Backpatch of 71e14cf3aa024496adcb23e83ddf13a7c5ddeb32

comment:10 by Preston Holmes <preston@…>, 12 years ago

In 9979c12f4a13a707fbfdd01f1694864fa53b6e6a:

Fixed #18347 -- Removed autofield raw SQL inserts from tests

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