﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
32851	GenericRelation inherited from Abstract model in different app fails to generate migration	Foucauld Degeorges	nobody	"I'm trying to create a new model in a new app B, inheriting from an abstract model in app A:

{{{
# app_b/models.py
from app_a.models import Foo

class ConcreteModel(Foo):
   pass
}}}

`Foo` has a GenericRelation to another model of app A:

{{{
# app_a/models.py
from django.contrib.contenttypes.fields import GenericRelation

class Foo(models.Model):
    class Meta:
        abstract = True
    
    some_relation = GenericRelation(
        ""Bar"",
        content_type_field=""foo_type"",
        object_id_field=""foo_id""
    )

class Bar(models.Model):
    # whatever
}}}

Generation of the initial migration of app B fails with the following SystemCheck errors:

{{{
<function GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors at 0x7fa2a6747c80>: (models.E022) <function GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors at 0x7fa2a6747c80> contains a lazy reference to app_b.bar, but app 'app_b' doesn't provide model 'bar'.
app_b.ConcreteModel.some_relation: (fields.E307) The field app_b.ConcreteModel.some_relation was declared with a lazy reference to 'app_b.bar', but app 'app_b' doesn't provide model 'bar'.
}}}

Indeed, app_b does not provide Bar, app_a does.

I tried explicitly mentioning app_a in the GenericRelation:

{{{
some_relation = GenericRelation(
    ""app_a.Bar"",
    content_type_field=""foo_type"",
    object_id_field=""foo_id""
)
}}}

but this does not generate a migration for app_a, nor does it fix the problem."	Bug	closed	Uncategorized	2.2	Normal	invalid			Unreviewed	0	0	0	0	0	0
