Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Allow polymorphic serializer to be defined as dotted string in PolymorphicResourceRelatedField #1087

Open
@Elawphant

Description

PolymorphicResourceRelatedField serializer throws 'str' object has no attribute 'get_polymorphic_types', if the referenced serializer is declared before the referencing serializer.

class ASerializer(ModelSerializer):
 ...
class BSerializer(ModelSerializer):
 A = PolymorphicResourceRelatedField(
 'module.serializers.ASerializer',
 ) # <- this one raises 'str' object has no attribute 'get_polymorphic_types', to avoid it we have to reference the class directly ASerializer
 C = PolymorphicResourceRelatedField(
 'module.serializers.ASerializer', # <- this one does not raise error
 )
 
class CSerializer(ModelSerializer):
 ...

'module.serializers.ASerializer' should be the preferred way of referencing other serializers to avoid circular imports.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /