django-polymorphic icon indicating copy to clipboard operation
django-polymorphic copied to clipboard

Reverse related object descriptor is overwritten on class

Open gracecodes144 opened this issue 11 years ago • 2 comments

This line overwrites the parent model class reverse related field object descriptor with a property function (at model instantiation), which breaks references to the field and its attributes for other interfaces. See this issue which arose in the implementation of a model relation introspection app on a model hierarchy using django-polymorphic

gracecodes144 avatar Apr 03 '14 18:04 gracecodes144

I guess its this line now: https://github.com/chrisglass/django_polymorphic/blob/master/polymorphic/polymorphic_model.py#L180

Any reason why you chose to do this? Any interest in finding a way around it (maybe metaclasses like Django itself uses)?

gracecodes144 avatar Apr 07 '14 20:04 gracecodes144

Hi! thanks for dropping a line.

This code makes sure that the .._ptr fields don't use a PolymorphicManager to access the base objects. Otherwise, you'd never be able to access it; the PolymorphicManager would immediately downcast the retrieved model back to the Child model.

If there is a better way (I guess a descriptor), that would be welcome to have! This fix should indeed happen in the metaclass, I find it a bit strange to see this code in the model class.

vdboor avatar Apr 25 '14 09:04 vdboor