Skip to content

Abstract base PolymorphicModels cause field name clashes #19

@julianwachholz

Description

@julianwachholz

In a scenario where your base PolymorphicModel is abstract (for example, when you don't need a "simple" Project, a ForeignKey on it will cause field name clashes:

class BaseProject(PolymorphicModel):
    owner = models.ForeignKey(User, related_name='projects')
    class Meta:
        abstract = True

class ArtProject(BaseProject):
    # add some fields
    pass

class ResearchProject(BaseProject):
    # add some fields
    pass

This will cause the following errors (when running ./manage.py validate):

app.artproject: Accessor for field 'owner' clashes with related field 'User.projects'. Add a related_name argument to the definition for 'owner'.
app.artproject: Reverse query name for field 'owner' clashes with related field 'User.projects'. Add a related_name argument to the definition for 'owner'.
app.artproject: Accessor for field 'owner' clashes with related field 'User.projects'. Add a related_name argument to the definition for 'owner'.
app.artproject: Reverse query name for field 'owner' clashes with related field 'User.projects'. Add a related_name argument to the definition for 'owner'.

Same output for ResearchProject, the error gets printed twice for every model.

Is this by design or is a fix possible?
Some kind of workaround at the moment is defining the base model as not abstract, obviously at the cost of SQL overhead/performance.

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