deschler / django-modeltranslation

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

Issue with foreign keys defined in "app.ModelName" format in abstract base classes #730

Open benzkji opened 2 months ago

benzkji commented 2 months ago

Somehow the field.model is not yet a class, but still a string, in this particular case.

Tried a fix (modeltranslation/fields.py), but issue seems deeper, I guess it should really just not be a string?

This PR just shows the problem.

benzkji commented 2 months ago

This issue arose during #727 and #729

last-partizan commented 2 months ago

Probably, yes. We expect there a model, not a string.

benzkji commented 2 months ago

But in this edge case, it is a string. Nothing special, or do you see something special in my example code? Defining foreign key field's models as strings is supported and sometimes necessary, in Django, so shouldn't it be with modeltranslation?

last-partizan commented 2 months ago

That looks like error, or maybe we're accessing it at the wrong time (during init).

If you look at any other foreign key, field.model is a model class, even if it's string in the definition.

benzkji commented 2 months ago

Agreed. Hard to tackle down. It's really only when in an abstract base class.