#36239: ManyToManyField check error with invalid "to" when passing
through/through_fields
-------------------------------------+-------------------------------------
     Reporter:  Jordan Hyatt         |                    Owner:
                                     |  JaeHyuckSa
         Type:  Bug                  |                   Status:  assigned
    Component:  Core (System         |                  Version:  5.1
  checks)                            |
     Severity:  Normal               |               Resolution:
     Keywords:  check                |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  1                    |  Patch needs improvement:  1
Easy pickings:  1                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Tanishq):

 Hey Django Team,

 I’d love to jump on ticket #36239 (ManyToManyField crash with invalid to).
 Can you assign it to @Amaan-ali03? I’ve dug into the issue and want to
 implement the fix.

 Issue:
 An invalid to (e.g., "Fo") with t**hrough/through_fields** crashes with
 **AttributeError**: 'str' has no '_meta' because r**elated_model** isn’t
 handled properly.

 Proposed Fix:
 Update **_check_relationship_model in django/db/models/fields/related.py**
 with a type check:


 {{{
 related_object_name = (
     related_model if isinstance(related_model, str) else
 related_model._meta.object_name
 )
 errors.append(
     checks.Error(
         f"'{through._meta.object_name}.{field_name}' is not a foreign key
 to '{related_object_name}'.",
         obj=self,
     )
 )
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36239#comment:10>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070195b98a4343-36eea46b-65cb-4d6d-aeee-514f71d82056-000000%40eu-central-1.amazonses.com.

Reply via email to