django-cms / django-filer

File and Image Management Application for django
https://django-filer.readthedocs.io/
Other
1.73k stars 574 forks source link

fix: File.objects.only("id") query when deleting a user #1357

Closed fsbraun closed 1 year ago

fsbraun commented 1 year ago

Description

This PR is a cherry-pick of #1308 plus a simple test to verify that deleting users work. Thank you @wiltso for providing this fix!

When deleting a User object, Django's django.db.models.deletion.Collector will make a query like this: File.objects.filter(owner=user).only("id"). This then leads to a recursion error due to that the filer.models.File object requires that the following fields are present:

Related resources

Checklist

codecov[bot] commented 1 year ago

Codecov Report

Merging #1357 (a39996b) into master (35d4b8e) will increase coverage by 0.05%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1357      +/-   ##
==========================================
+ Coverage   72.35%   72.41%   +0.05%     
==========================================
  Files          72       72              
  Lines        3277     3284       +7     
  Branches      534      534              
==========================================
+ Hits         2371     2378       +7     
  Misses        739      739              
  Partials      167      167              
Impacted Files Coverage Δ
filer/models/filemodels.py 85.65% <100.00%> (+0.45%) :arrow_up: