Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#11750 closed (worksforme)

ManyToMany field does not respect Proxy models

Reported by: mxposed Owned by: nobody
Component: Database layer (models, ORM) Version: 1.1
Severity: Keywords: manytomany proxy
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi

I have a proxy model above django.contrib.auth.models.User
and i have a ManyToMany field referencing to django.contrib.auth.models.User

When i try to add an instance of my proxy class to the field i get the TypeError: 'user' instance expected

class MyUser(User):
     class Meta:¶
         proxy = True

class Item(models.Model):
    owners = models.ManyToManyField(User)

Item.objects.get(fk=1).owners.add(MyUser.objects.get(fk=1))

Change History (2)

comment:1 Changed 6 years ago by emulbreh

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I cannot reproduce this with r11638.

import unittest
from django.db import models
from django.contrib.auth.models import User

class A(User): 
    class Meta:
        proxy=True
        
class B(models.Model):
    a_set = models.ManyToManyField(A)
    
class T11750(unittest.TestCase):
    def test_11750(self):        
        user = User.objects.create(username="foo")
        a = A.objects.get()
        b = B.objects.create()
        b.a_set.add(a)

comment:2 Changed 6 years ago by emulbreh

There's an error in my test: a_set should point to User. But still not reproducible.

import unittest
from django.db import models
from django.contrib.auth.models import User

class A(User): 
    class Meta:
        proxy=True
        
class B(models.Model):
    a_set = models.ManyToManyField(User)
    
class T11750(unittest.TestCase):
    def test_11750(self):        
        user = User.objects.create(username="foo")
        a = A.objects.get()
        b = B.objects.create()
        b.a_set.add(a)
        
Note: See TracTickets for help on using tickets.
Back to Top