Opened 9 years ago

Closed 9 years ago

#11230 closed (invalid)

Assigning the super class of a Proxy class to a ForeignKey fails.

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


from django.db import models
from proj.myapp.models import ProxyClass

class NewClass(models.Model):
    proxy = models.ForeignKey(ProxyClass,related_name="newclass",unique=True)

Failure stacktrace on save():

>> n.proxy = p  # p is actually an instance of SuperClass
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "...lib/common/django/db/models/fields/", line 272, in __set__,
ValueError: Cannot assign "SuperClass": "NewClass.proxy" must be a "Proxy" instance.

First ticket for me, so let me know if I can provide more info.


Change History (4)

comment:1 Changed 9 years ago by David Novakovic

Component: UncategorizedDatabase layer (models, ORM)

comment:2 Changed 9 years ago by David Novakovic

Sorry - that should be on assignment, not save.

comment:3 Changed 9 years ago by David Novakovic

To clarify a few more details:

  • The model validates fine, tables are created with syncdb etc.
  • The SuperClass is a fully fledged db.models.Model.
  • Proxy is a proxy class that extends SuperClass but has no table in the DB.
class Proxy(SuperClass):
    def proxy_behaviour(self):

    class Meta:
        proxy = True

Hope that helps a bit more...

comment:4 Changed 9 years ago by Alex Gaynor

Resolution: invalid
Status: newclosed

This is perfectly consistant behavior, if you expect a specific class (proxy or otherwise) and you assign a superclass of it it will not be accepted.

Note: See TracTickets for help on using tickets.
Back to Top