Opened 3 years ago

Last modified 8 months ago

#18088 new Cleanup/optimization

Add a "supports_foreign_key" database feature to ease testing

Reported by: akaariai 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

Description

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/tests.py. 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 akaariai 3 years ago.

Download all attachments as: .zip

Change History (10)

Changed 3 years ago by akaariai

comment:1 Changed 3 years ago by claudep

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

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

comment:2 Changed 3 years ago by akaariai

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

comment:3 Changed 3 years ago by russellm

@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 3 years ago by akaariai

  • Has patch set

Understood.

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 3 years ago by aaugustin

  • Triage Stage changed from Unreviewed to Design 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 2 years ago by aaugustin

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

comment:7 Changed 2 years ago by akaariai

  • Triage Stage changed from Design decision needed to Accepted

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 13 months ago by timo

  • Patch needs improvement set

Patch no longer applies cleanly.

comment:9 Changed 8 months ago by timgraham

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