Opened 8 years ago

Last modified 6 years ago

#18088 new Cleanup/optimization

Add a "supports_foreign_key" database feature to ease testing

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Testing framework Version: 1.4
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Currently our test coverage for checking that foreign keys are properly enforced in the database are almost non-existent. One reason for this is that it has not been easy to write tests, as some backends do not support foreign keys and information of foreign key support has not been available as !skipUnlessDBFeature target.

The attached patch adds a new database feature "supports_foreign_keys". The patch also uses this feature in regressiontests/backends/ The test results for backends tests are similar pre/post patch. MySQL + MyISAM fails one test both pre/post patch, other backends work correctly.

This patch is needed for writing proper tests for #18081 for example.

Attachments (1)

18088.diff (4.8 KB) - added by Anssi Kääriäinen 8 years ago.

Download all attachments as: .zip

Change History (10)

Changed 8 years ago by Anssi Kääriäinen

Attachment: 18088.diff added

comment:1 Changed 8 years ago by Claude Paroz

I wonder if we really need both can_introspect_foreign_keys and supports_foreign_key... Could you investigate?

comment:2 Changed 8 years ago by Anssi Kääriäinen

Surprisingly we can introspect foreign keys on SQLite, but they are not enforced. Worth a comment though.

comment:3 Changed 8 years ago by Russell Keith-Magee

@akaariai -- they're not enforced *currently*, but they could be. Foreign key constraints were only added in SQLite 3.6.19 (see #14204); Django's SQLite backend doesn't currently provide any way to exploit them.

comment:4 Changed 8 years ago by Anssi Kääriäinen

Has patch: set


Main point is that supports_foreign_keys is not always the same as can_introspect_foreign_keys. It would be actually possible to check if the SQLite backend supports foreign keys in the _supports_foreign_keys() call of SQLite. I am not going to piggy-back that change into this ticket. The current changes are relatively simple, SQLite foreign key support is not.

comment:5 Changed 8 years ago by Aymeric Augustin

Triage Stage: UnreviewedDesign decision needed

Sqlite 3.6.19 was released nearly three years ago. Debian stable ships Sqlite 3.7.3.

Shouldn't we at some point:

  • have a minimal version requirement for Sqlite,
  • deprecate support for MySQL + MyISAM,

and support only "sane" databases -- that is, databases that enforce foreign keys?

This is well beyond the scope of this ticket, but I'm not thrilled by the idea of adding code to deal with broken databases. Make that a -0...

comment:6 Changed 7 years ago by Aymeric Augustin

Can we make a decision? Anssi, it's your call.

comment:7 Changed 7 years ago by Anssi Kääriäinen

Triage Stage: Design decision neededAccepted

I think that as long as we have databases that do not support foreign keys then supports_foreign_keys flag is needed. So, accepted. This could of course be closed if somebody were to remove all databases without foreign key support.

comment:8 Changed 6 years ago by Tim Graham

Patch needs improvement: set

Patch no longer applies cleanly.

comment:9 Changed 6 years ago by Tim Graham

The supports_foreign_keys flag was added in d683263f97aedd67f17f4b78ac65d915f4e70d36, but there are still bits of the proposed patch that could be applied.

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