#32676: Migration autodetector changes related_name for self-referential
ManyToManyField.
----------------------------------+--------------------------------------
Reporter: Mariusz Felisiak | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 4.0
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Comment (by David Wobrock):
Hi,
Similarly to #32675, on a first and very quick look, the `ManyToManyField`
has some logic at
`django.db.models.fields.related.ManyToManyField.contribute_to_class` that
looks very much like the names described in the ticket itself:
{{{
def contribute_to_class(self, cls, name, **kwargs):
# To support multiple relations to self, it's useful to have a
non-None
# related name on symmetrical relations for internal reasons. The
# concept doesn't make a lot of sense externally ("you want me to
# specify *what* on my non-reversible relation?!"), so we set it
up
# automatically. The funky name reduces the chance of an
accidental
# clash.
if self.remote_field.symmetrical and (
self.remote_field.model == RECURSIVE_RELATIONSHIP_CONSTANT or
self.remote_field.model == cls._meta.object_name
):
self.remote_field.related_name = "%s_rel_+" % name
elif self.remote_field.is_hidden():
# If the backwards relation is disabled, replace the original
# related_name with one generated from the m2m field name.
Django
# still uses backwards relations internally and we need to
avoid
# clashes between multiple m2m fields with related_name ==
'+'.
self.remote_field.related_name = '_%s_%s_%s_+' % (
cls._meta.app_label,
cls.__name__.lower(),
name,
)
}}}
Since `_meta` should not be available anymore, I expect that the result
of the `self.remote_field.model == cls._meta.object_name` condition
changed, because we should not be able to use `cls._meta.app_label`.
I'm open to help if we have an idea about how we can fix this :)
--
Ticket URL: <https://code.djangoproject.com/ticket/32676#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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.ea65dce736d74ea66ee1dba88280bb9f%40djangoproject.com.