Modify

Ticket #294 (closed defect: fixed)

Opened 5 years ago

Last modified 4 years ago

Acessing ManyToMany field pulls the wrong relationship

Reported by: hcarvalhoalves@… Owned by: andrew
Priority: critical Milestone: 0.7
Component: migrations Version: 0.6.1
Keywords: Cc:

Description

During the migration, accessing a ManyToMany? manager brings the wrong instances. E.g., given the 2 models:

class Client(models.Model):
    ...

class Property(models.Model):
    owner = models.ForeignKey(Client, null=True)
    interested = models.ManyToManyField(Client, related_name='interests')

If during the migration, I try to access the relationship:

    for property in orm['property.Property'].objects.all():
        clients = property.interested.all()

clients contains the equivalent of calling property.owner, instead of the expected M2M relationships.

Attachments

client_models.py (1.1 KB) - added by anonymous 5 years ago.
Client app models
property_models.py (8.8 KB) - added by anonymous 5 years ago.
Property app models
migration.py (16.4 KB) - added by anonymous 5 years ago.
Migration where the bug shows

Change History

comment:1 Changed 5 years ago by anonymous

I'm stuck on that one. Have no idea how to access the M2M relationship correctly.

Changed 5 years ago by anonymous

Client app models

Changed 5 years ago by anonymous

Property app models

Changed 5 years ago by anonymous

Migration where the bug shows

comment:2 Changed 5 years ago by anonymous

Found a quick solution for anyone having the same issue.

In the case of the models defined above, one can access the relation with the equivalent of the accessors using filter():

        for client in orm['client.Client'].objects.all():
            orm['property.Property'].objects.filter(interested__in=[client])

comment:3 Changed 5 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.6.3

I'll have a proper look at this shortly, I promise. In the meantime, please use the workaround above.

Note to self: Reconstructing ORMs from nothing is hard.

comment:4 Changed 4 years ago by andrew

  • Milestone changed from 0.6.3 to 0.7

comment:5 Changed 4 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed

This has now been confirmed as fixed in 0.7.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.