Code

Opened 6 years ago

Closed 6 years ago

#6758 closed (invalid)

Multiple 'self' referencing ManyToManyFields in one model overwrite each other's data

Reported by: notanumber Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: ManyToManyField, self, multiple
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Defining multiple ManyToManyFields in one model is problematic. When updating one field, all of the others are updated with the same data.

For example, in the following model:

from django.db import models

class Job(models.Model):
    
    title = models.CharField(max_length=100)
    reports_to = models.ManyToManyField('self', null=True, blank=True, related_name='reports_to_set')
    supervises = models.ManyToManyField('self', null=True, blank=True, related_name='supervises_set')

    class Admin:
        pass
        
    def __unicode__(self):
        return self.title

Updating a user's data, "Bill", 'reports_to' to read "John", also sets 'supervises' to "John" as well. Obviously, in this case at least, this is not the desired behaviour.

Adding symmetrical=False does not correct this issue, but raises another: When updating "Bill" to 'reports_to' "John", we end up with both users having "John" & "Bill" in their 'reports_to' & 'supervises' fields.

Tested this on WindowsXP, using SQLite3 & the built-in 'runserver' command.

The test application & project is attached to this ticket. The admin user/password is "test"/"test123"

Attachments (1)

testm2m.zip (8.4 KB) - added by David Sauve <dnsauve@…> 6 years ago.
Test appliction and project

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by David Sauve <dnsauve@…>

Test appliction and project

comment:1 Changed 6 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I'm unable to replicate any of the problems here. I never have the reports_to field being updated when the supervises field is set, or vice-versa. I also always have the various many-to-many fields containing exactly the information I set them to. This is the same whether I use the shell or the admin interface (using trunk's subversion code).

Can you please give step-by-step instructions starting from a clean database of how you create even one of these problems.

comment:2 Changed 6 years ago by David Sauve

  • Resolution set to invalid
  • Status changed from new to closed

Hmmm. I can't seem to replicate this issue myself, anymore.

Maybe it was a side effect of something else? Guess I'll withdraw this bug.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


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

 
Note: See TracTickets for help on using tickets.