#30409: System check E012 erroneously raised when ForeignKey is used in compound
index
------------------------------------------------+------------------------
               Reporter:  tr00st                |          Owner:  nobody
                   Type:  Bug                   |         Status:  new
              Component:  Core (System checks)  |        Version:  2.2
               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                     |
------------------------------------------------+------------------------
 Looks to be an issue with the implementation in #28714 - issue found
 whilst upgrading from 2.0 to 2.2, but also occurs in latest 2.1.x.

 To duplicate, create a compound index including the ID for a ForeignKey,
 eg:

 {{{#!python

 class DataConcentrator(models.Model):
     #...

 class ConcentratorHeartbeat(models.Model):
     #...
     class Meta:
         indexes = [
             models.Index(fields=["source_id", "-collected_at"]),
         ]
     #...
     source = models.ForeignKey(DataConcentrator, null=True,
 related_name="heartbeats", on_delete=models.CASCADE)
 }}}

 Expected behaviour:
 No errors raised

 Encountered behaviour:
 Error raised on system check:

 {{{
 Performing system checks...

 Unhandled exception in thread started by <function
 check_errors.<locals>.wrapper at 0x00000298392F3D08>
 Traceback (most recent call last):
   File "C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-
 packages\django\utils\autoreload.py", line 225, in wrapper
     fn(*args, **kwargs)
   File "C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-
 packages\django\core\management\commands\runserver.py", line 117, in
 inner_run
     self.check(display_num_errors=True)
   File "C:\Workspace\sensor-analytics-tool\.pyenv\lib\site-
 packages\django\core\management\base.py", line 425, in check
     raise SystemCheckError(msg)
 django.core.management.base.SystemCheckError: SystemCheckError: System
 check identified some issues:

 ERRORS:
 sensor_receiver.ConcentratorHeartbeat: (models.E012) 'indexes' refers to
 the nonexistent field 'source_id'.

 System check identified 2 issues (0 silenced).
 }}}

 Current workaround is to just silence E012. Gets things running, but
 obviously not ideal.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30409>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.e102e2c4148828d3d0d3d5ea3cb6c54f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to