Opened 7 years ago

Closed 7 years ago

#11230 closed (invalid)

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

Reported by: dpn 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 7 years ago by dpn

  • Component changed from Uncategorized to Database layer (models, ORM)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 7 years ago by dpn

Sorry - that should be on assignment, not save.

comment:3 Changed 7 years ago by dpn

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 7 years ago by Alex

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

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