Opened 16 years ago
Closed 16 years ago
#10112 closed (worksforme)
Python Crash with ORM Inheritance
Reported by: | 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: | no | UI/UX: | no |
Description (last modified by )
This bug causes a reproducible crash in the python interpreter [python issue5014] on my system, so I can't give a specific traceback, but I believe that an infinite recursion is generated when I try and use the db_column in a TextField.
Basically, I'm modifying one of my models to allow inheritance of a field so rather than keep the existing field which cannot be overridden with a function in the subclass, I'm creating a property to access the field - ie:
class Foo(model): _bar = TextField(db_column = 'bar') bar = property(lambda x: x.bar) class Bla(Foo): @property def bar(self): whatever
I think the db_column = 'bar' causes problems as there is a Foo.bar attribute so somewhere in the model this is screwing things up by making an infinite loop which for some reason is breaking the python runtime.
Reproducible with revision 9787
Change History (3)
comment:1 by , 16 years ago
Description: | modified (diff) |
---|
comment:3 by , 16 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
This is working fine for me:
In [1]: from django.db import models In [2]: class Foo(models.Model): ...: _bar = models.TextField(db_column='bar') ...: bar = property(lambda self: self._bar) ...: ...: --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /home/alex/<ipython console> in <module>() /usr/lib/python2.5/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs) 49 # For 'django.contrib.sites.models', this would be 'sites'. 50 model_module = sys.modules[new_class.__module__] ---> 51 kwargs = {"app_label": model_module.__name__.split('.')[-2]} 52 else: 53 kwargs = {} IndexError: list index out of range In [3]: class Foo(models.Model): _bar = models.TextField(db_column='bar') bar = property(lambda self: self._bar) ...: class Meta: ...: app_label = '' ...: ...: In [6]: class Bla(Foo): ...: bar = pro projects/alexs_language projects/euler property projects/chatlog projects/hoogstraten projects/election_sim projects/pinax ...: bar = property(lambda self: "a") ...: ...: --------------------------------------------------------------------------- IndexError Traceback (most recent call last) /home/alex/<ipython console> in <module>() /usr/lib/python2.5/site-packages/django/db/models/base.pyc in __new__(cls, name, bases, attrs) 49 # For 'django.contrib.sites.models', this would be 'sites'. 50 model_module = sys.modules[new_class.__module__] ---> 51 kwargs = {"app_label": model_module.__name__.split('.')[-2]} 52 else: 53 kwargs = {} IndexError: list index out of range In [7]: class Bla(Foo): bar = property(lambda self: "a") ...: class Meta: ...: app_label = '' ...: ...: In [9]: Foo.bar Out[9]: <property object at 0x8d2c5cc> In [10]: Foo().bar Out[10]: '' In [11]: Foo(_bar='a').bar Out[11]: 'a' In [12]: Bla().bar Out[12]: 'a' In [13]: Bla(_bar="f").bar Out[13]: 'a'
There's some debugging cruft in there because I was working from the shell, but it seems to work fine,
edited for readability, please use the preview feature :)