-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow polymorphic serializer to be defined as dotted string in PolymorphicResourceRelatedField #1087
Comments
Thanks for reporting. It can be debated whether this is a bug or a feature request. Currently, PR is very welcome. Code line which I guess needs to be adjused is around this line. |
Setting a dynamic import on |
What does |
if there was no circular import issue, we could just do
|
The LazySerializerDict only resolves the serializer from dotted string when accessed the first time. This should also be used in this case, it needs to be checked whether this resolves the issue fully in terms of circular imports though as the polymorphic meta class already accesses the serializer. |
It does not unfortunately. Since LazySerializerDict requires serializer, instead I used import_class_from_dotted_path. but it fails with circular imports I tried to extend
|
I haven't dived into this issue enough to really see what is the best approach. What I recommend you to do is to work on a PR with a test which setups the serializer the way you would like it to support it (including recursion and dotted strings). Then, if you find a solution which makes the test green, great and attach it to the PR. If you do not, simply open a PR with the failing test. This will be helpful to investigate this issue further. |
We want to think about how to continue supporting Django Polymorphic in the future. As this issue is about polymorphic support, I assume you are or have been using Django Polymorphic and DJA together. It would be very valuable if you could add your use case and feedback to our discussion at #1194 so we can make an informed decision. Thanks. |
My use case was Django Polymorphic with DJA with Ember.js data, which supports a local ORM with polymorphic model types (soon DSL instead of model classes). In my case polymorphism was helping reduce number of queries to the server for a number of data types which were essentially sub-types of single type. |
PolymorphicResourceRelatedField
serializer throws 'str' object has no attribute 'get_polymorphic_types', if the referenced serializer is declared before the referencing serializer.'module.serializers.ASerializer' should be the preferred way of referencing other serializers to avoid circular imports.
The text was updated successfully, but these errors were encountered: