#26163: Wrong related fields in ._meta.get_fields with multiple database on
foreignkey
-------------------------------------+-------------------------------------
     Reporter:  aRkadeFR             |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:  models, meta,        |             Triage Stage:
  get_fields, fields, router,        |  Unreviewed
  multiple, databases                |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by charettes):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Hi aRkadeFR,

 As you might be aware the ORM implements concrete model inheritance using
 [https://docs.djangoproject.com/en/1.9/topics/db/models/#multi-table-
 inheritance multi-table inheritance] with a unique foreign key
 (`OneToOneField`).

 In your case a your `GroupA` model could also be explicitly defined as:

 {{{#!python
 from django.contrib.auth.models import Group
 from django.db import models

 class GroupA(Group):
     group = models.OneToOneField(Group, parent_link=True)
 }}}

 Given your router definition it looks you're trying to define a cross-
 database relation, [https://docs.djangoproject.com/en/1.9/topics/db/multi-
 db/#cross-database-relations a feature documented as unsupported]. I can
 see you even explicitly tried to work around this limitations by
 overriding `allow_relation`.

 Without a full traceback it's hard to figure out from where the failure
 originates but I suppose a simple `GroupA.object.all()` should fail since
 it will be resolved to an SQL query `JOIN`ing the `Group` table.

 Now, the `_meta.get_field()` API '''always''' returned inherited fields
 from parents so this doesn't look like a bug to me. If you want to make
 sure the field is defined on a specific model you should access its
 `model` attribute.

 If you could provide a full traceback of the exception that was triggered
 during the emulated cascade deletion you might be able to get help from
 our support channels but given this is documented as unsupported I'll
 close the ticket as invalid.

--
Ticket URL: <https://code.djangoproject.com/ticket/26163#comment:2>
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/066.581cece6c08a8fee2304b5fff9f00437%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to