wagtailmedia icon indicating copy to clipboard operation
wagtailmedia copied to clipboard

Fix on-delete error when cleaning up thumbnails

Open jsma opened this issue 2 years ago • 1 comments

This fixes all cases where the code assumed a thumbnail was present, since thumbnails are actually optional.

jsma avatar Oct 14 '22 17:10 jsma

Thanks @jsma. I was thinking about this the other week while fixing a separate issue. Any chance you could add a test or two for the changes?

zerolab avatar Oct 14 '22 20:10 zerolab

I've added tests but this got a little complicated.

First, it wants to create a migration simple to add use_json_field=True to the StreamField used in the test app's models. This argument causes 2.15.x to fail, so I'm not sure what best practices are for handling this.

The other issue was that after I switched TestMediaDeleteView to inherit from TransactionTestCase (needed so the post-delete signal would actually fire on_commit), I ran into strange issues which required me to duplicate the bit of code to create the root collection. I tried using the test fixtures with a collection fixture added to it but this caused a couple errors I didn't want to sink any more time into.

jsma avatar Oct 17 '22 01:10 jsma

@jsma ah, the joy of supporting multiple versions!

I think the minimum you need to do is something like https://github.com/torchbox/wagtail-markdown/blob/main/tests/testapp/models.py#L23

On the transaction bit - have you seen https://adamj.eu/tech/2020/05/20/the-fast-way-to-test-django-transaction-on-commit-callbacks/ - our minimum Django requirement is 3.2 so this should be supported

zerolab avatar Oct 17 '22 09:10 zerolab

Thank you @jsma, merged in a63c411 and parents. I tidied up the tests to use with self.captureOnCommitCallbacks(execute=True) wherever it was needed

zerolab avatar Oct 24 '22 08:10 zerolab