Opened 19 months ago

Closed 19 months ago

Last modified 19 months ago

#34456 closed Uncategorized (invalid)

Add a way to set allow_cascade=True in _fixture_teardown()

Reported by: Howard Cox Owned by: nobody
Component: Testing framework Version: 4.2
Severity: Normal Keywords:
Cc: Tom Carrick Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Howard Cox)

We use https://github.com/schlunsen/django-timescaledb as our database backend and ran into a problem with some of our tests for django migrations on tables using timescale compression.

I [wrote up our problem on django-timescaledb back in October (https://github.com/schlunsen/django-timescaledb/issues/40) but it essentially boils down to:

  • django.test.testcases.TransactionTestCase._fixture_teardown() calls django.db.backends.postgresql.operations.sql_flush() and truncates every table at the end of tests.
  • In timescaledb, compressed hypertables create "chunks" as tables with a subset of the hypertable's data.
  • Because we have foreign keys in some of our hypertables, the chunk tables also get that foreign-key rule.
  • Those chunk tables are transparent to Django, and so are not in the list to be truncated.
  • And so, the truncation fails, because the chunk tables still reference some of the data being truncated.

The easiest solution seems to be to allow _fixture_teardown() to opt-in to setting allow_cascade=True when truncating.

We're happy to submit a PR if this proposal gets accepted.

Change History (4)

comment:1 by Howard Cox, 19 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 19 months ago

Resolution: needsinfo
Status: newclosed

As far as I'm aware, it's an issue in timescaledb, they could override ops.sql_flush() and add flushing "chunks".

comment:3 by Mariusz Felisiak, 19 months ago

Resolution: needsinfoinvalid

comment:4 by Howard Cox, 19 months ago

That's fair, it's been abandoned anyway so we're considering forking it, so can just change it.

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