How can I replace the ORM class - so it should not cause recursion !!!
Problem:
original class has the super call, when its got replaced - it causes self inheritance and causes maximum recursion depth exceed exception.
i.e. class orm is calling super(orm, self).... and orm has been replaced by another class which inherits original orm....
Package !
addons __init__.py osv run_app.py
./addons:
__init__.py test_app1.py test.py
./osv:
__init__.py orm.py
contents of orm.py
class orm_template(object):
def __init__(self, *args, **kw):
super(orm_template, self).__init__()
def fields_get(self, fields):
return fields
def browse(self, id):
return id
class orm(orm_template):
def __init__(self, *args, **kw):
super(orm, self).__init__(*args, **kw)
def fields_get(self, fields, context = None):
return super(orm, self).fields_get(fields)
def read(self, fields):
return fields
contents of addons/init.py
import test
def main(app):
print "Running..."
__import__(app, globals(), locals())
contents of addons/test.py
from osv import orm
import osv
class orm(orm.orm):
def __init__(self, *args, **kw):
super(orm, self).__init__(*args, **kw)
def fields_get(self, *args, **kw):
print "my fields get................."
return super(orm, self).fields_get(*args, **kw)
osv.orm.orm = orm
print "replaced.........................."
contents of test_app1.py
from osv.orm import orm
class hello(orm):
_name = 'hellos'
def __init__(self, *args, **kw):
super(hello, self).__init__(*args, **kw)
print hello('test').fields_get(['name'])
contents of run_app.py
import addons
addons.main('test_app1')
OUTPUT
>>>python run_app.py
replaced..........................
Running...
...
...
super(orm, self).__init__(*args, **kw)
RuntimeError: maximum recursion depth exceeded
I've seen the similar question