Skip to content
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

Clashing Accessor and Query Name when inheriting across apps #516

Closed
matthew-nm opened this issue Apr 23, 2022 · 1 comment
Closed

Clashing Accessor and Query Name when inheriting across apps #516

matthew-nm opened this issue Apr 23, 2022 · 1 comment

Comments

@matthew-nm
Copy link

matthew-nm commented Apr 23, 2022

Hi,

I have a Django project with three separate apps, 'mainapp', 'app1', and 'app2'. The mainapp has a polymorphic model UniversalBaseSet, and app1 and app2 each have a model BaseSet which subclass from UniversalBaseSet.

Django gives me the following error:

app1.BaseSet.universalbaseset_ptr: (fields.E304) Reverse accessor for 'BaseSet.universalbaseset_ptr' clashes with reverse accessor for 'BaseSet.universalbaseset_ptr'.
        HINT: Add or change a related_name argument to the definition for 'BaseSet.universalbaseset_ptr' or 'BaseSet.universalbaseset_ptr'.
app1.BaseSet.universalbaseset_ptr: (fields.E305) Reverse query name for 'BaseSet.universalbaseset_ptr' clashes with reverse query name for 'BaseSet.universalbaseset_ptr'.
        HINT: Add or change a related_name argument to the definition for 'BaseSet.universalbaseset_ptr' or 'BaseSet.universalbaseset_ptr'.
app2.BaseSet.universalbaseset_ptr: (fields.E304) Reverse accessor for 'BaseSet.universalbaseset_ptr' clashes with reverse accessor for 'BaseSet.universalbaseset_ptr'.
        HINT: Add or change a related_name argument to the definition for 'BaseSet.universalbaseset_ptr' or 'BaseSet.universalbaseset_ptr'.
app2.BaseSet.universalbaseset_ptr: (fields.E305) Reverse query name for 'BaseSet.universalbaseset_ptr' clashes with reverse query name for 'BaseSet.universalbaseset_ptr'.
        HINT: Add or change a related_name argument to the definition for 'BaseSet.universalbaseset_ptr' or 'BaseSet.universalbaseset_ptr'.

Having worked with django-polymorphic before I know the _ptr is referring to the reference to the parent, but I don't know exactly what the issue is. Why does it look like each accessor or query name is clashing with itself?

Thanks for any help!

@matthew-nm
Copy link
Author

I guess this is more of a Django thing than a django-polymorphic thing which makes sense given what django-polymorphic is doing (and not doing) under the hood.

It seems django is creating a OneToOneField in the background, so the solution is to create that field explicitly in the child models and set a related_name value to avoid the issue. https://stackoverflow.com/a/40344663/7144234

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant