deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.34k stars 257 forks source link

Translated foreign key in an abstract base class: foreign key instances cannot be deleted. #727

Open benzkji opened 2 months ago

benzkji commented 2 months ago

I have a abstract Link base class, used for my Teaser and ContentNav models. The base class has a field file, that is then translated in each of the real classes. The file field is a FileField from django-filer, so basically a ForeignKey.

When I try to delete a File instance, I get a TypeError / Cannot combine queries on two different base models. from django itself. The file field is configured as on_delete=models.SET_NULL, and as far as I can tell, the error happens because django wants to update all the needed foreign key fields, but somehow gets two querysets of different models (the two translated above) to combine and update. Why exactly is very hard to tell.

Has this happend before? I'll try to write a test, to rebuild the error - it currently happens in an old project, that was updated several times.

last-partizan commented 2 months ago

I'm not sure.

Do you get this error when you disable django-modeltranslation?

benzkji commented 2 months ago

I'm not sure, will try.

benzkji commented 2 months ago

Indeed, if I disable translation on one of the translated models, deletion is possible. I'll try to write a test, seems like a very edge case.

benzkji commented 2 months ago

please see PR, need directions for adding migrations :)

benzkji commented 2 months ago

The PR: #729