#35654: SystemCheckError on GenericRelation with lazy reference
-------------------------------------+-------------------------------------
     Reporter:  Giannis Terzopoulos  |                     Type:  Bug
       Status:  new                  |                Component:  Database
                                     |  layer (models, ORM)
      Version:  5.0                  |                 Severity:  Normal
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 Let's consider having 2 apps, `core` and `bookmarks`. Then I add a new
 `TaggetItem` model to `core`:
 {{{#!python
 class TaggedItem(models.Model):
     content_type = models.ForeignKey(ContentType,
 on_delete=models.CASCADE)
     object_id = models.PositiveIntegerField()
     content_object = GenericForeignKey()
 }}}

 and a new `Bookmark` model to `bookmarks`:
 {{{#!python
 class Bookmark(models.Model):
     tags = GenericRelation('core.TagedItem')
 }}}

 Running `makemigrations` here I am getting:
 {{{
 SystemCheckError: System check identified some issues:

 ERRORS:
 <function
 
GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors
 at 0x7a08cdb98e00>: (models.E022) <function
 
GenericRelation.contribute_to_class.<locals>.make_generic_foreign_order_accessors
 at 0x7a08cdb98e00> contains a lazy reference to core.tageditem, but app
 'core' doesn't provide model 'tageditem'.
 bookmarks.Bookmark.tags: (fields.E307) The field bookmarks.Bookmark.tags
 was declared with a lazy reference to 'core.tageditem', but app 'core'
 doesn't provide model 'tageditem'.
 }}}

 The same happens if I `makemigrations` after adding TaggedItem, then add
 Bookmark and run `makemigrations` again.
 It doesn't happen if I `migrate` for TaggedItem, then add Bookmark and
 `makemigrations`.

 It also doesn't happen if I import `TaggedItem` and use that in
 `GenericRelation`:
 {{{#!python
 from core.models import TaggedItem


 class Bookmark(models.Model):
     tags = GenericRelation(TaggedItem)
 }}}

 The downside of this in my initial use case was that I would have to work
 around circular import errors, which wasn't easily doable.

 Finally, having both models in the same app/models.py doesn't trigger the
 error either, so it seems to be as if something is missing here.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35654>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701910f57c3d9-f6007c64-74c0-4d3c-aabb-69fe5ac343db-000000%40eu-central-1.amazonses.com.

Reply via email to