res.* osv.osv objects may be read() before being fully initialized

Reported by Ferdinand on 2009-11-05
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
OpenERP Server
Wishlist
OpenERP's Framework R&D

Bug Description

trying to implement
https://blueprints.launchpad.net/openobject-addons/+spec/accounting-period-jail

adding this code to account/account.py

class users(osv.osv):
    _name = 'res.users'
    _inherit = 'res.users'
    _columns = {
         'period_id': fields.many2one('account.period', 'Period Accounting', help='Jail for accounting date entry'),
    }
users()

causes this error - the period_id s not added.

[2009-11-05 18:00:09,054] INFO:init:module account: creating or updating database tables
[2009-11-05 18:00:09,858] DEBUG:sql:bad query: SELECT "menu_id","address_id","period_id","active","context_lang","password","context_tz","name","company_id","signature","login","action_id",id FROM "res_users" WHERE id IN (1) ORDER BY id
[2009-11-05 18:00:09,859] DEBUG:sql:[01]: column "period_id" does not exist
[2009-11-05 18:00:09,860] DEBUG:sql:[02]: LINE 1: SELECT "menu_id","address_id","period_id","active","context_...
[2009-11-05 18:00:09,860] DEBUG:sql:[03]: ^
Traceback (most recent call last):
  File "./openerp-server.py", line 111, in <module>
    pooler.get_db_and_pool(db, update_module=tools.config['init'] or tools.config['update'])
  File "/home/terp/OpenERP/branch/server/5.0/bin/pooler.py", line 40, in get_db_and_pool
    addons.load_modules(db, force_demo, status, update_module)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line 728, in load_modules
    r = load_module_graph(cr, graph, status, report=report)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line 581, in load_module_graph
    init_module_objects(cr, package.name, modules)
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line 366, in init_module_objects
    result = obj._auto_init(cr, {'module': module_name})
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 1875, in _auto_init
    default = self._defaults[k](self, cr, 1, {})
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/account/account.py", line 1306, in _default_company
    if user.company_id:
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 229, in __getattr__
    return self[name]
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 190, in __getitem__
    datas = self._table.read(self._cr, self._uid, ids, fffields, context=self._context, load="_classic_write")
  File "/home/terp/OpenERP/branch/server/5.0/bin/addons/base/res/res_user.py", line 128, in read
    result = super(users, self).read(cr, uid, ids, fields, context, load)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 2142, in read
    result = self._read_flat(cr, user, select, fields, context, load)
  File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 2212, in _read_flat
    self._order), sub_ids)
  File "/home/terp/OpenERP/branch/server/5.0/bin/sql_db.py", line 76, in wrapper
    return f(self, *args, **kwargs)
  File "/home/terp/OpenERP/branch/server/5.0/bin/sql_db.py", line 120, in execute
    res = self._obj.execute(query, params)
psycopg2.ProgrammingError: column "period_id" does not exist
LINE 1: SELECT "menu_id","address_id","period_id","active","context_...

Jan Verlaan (jan-verlaan) wrote :

I can not help you with your bug, but please take care of the used English while developing new code as help='Jail for accounting date'
jail is a synoniem for prison.
Better to use something that is clear for all users like: help='Check and accept accounting period' Perhaps you have even a better description.

See discussion http://openobject.com/wiki/index.php/English_Improvements#A-Z

Download full text (4.4 KiB)

many time I face similar problem , when I try to add new field to existing
object
server restart may solve this problem
if problem persist first compile the source code with python , then update
your module list and then upgarde particular module

for compiling use python2.5 /path-to -addons/modulename/__init__.py

hope this will solve your problem otherwise feel free to contact

On Thu, Nov 5, 2009 at 11:33 PM, Jan Verlaan (Veritos)
<email address hidden>wrote:

> I can not help you with your bug, but please take care of the used English
> while developing new code as help='Jail for accounting date'
> jail is a synoniem for prison.
> Better to use something that is clear for all users like: help='Check and
> accept accounting period' Perhaps you have even a better description.
>
> See discussio
> http://openobject.com/wiki/index.php/English_Improvements#A-Z
>
> --
> error trying to add column to class users(osv.osv)
> https://bugs.launchpad.net/bugs/475621
> You received this bug notification because you are subscribed to
> OpenObject Addons.
>
> Status in OpenObject Addons Modules: New
>
> Bug description:
> trying to implement
>
> https://blueprints.launchpad.net/openobject-addons/+spec/accounting-period-jail
>
> adding this code to account/account.py
>
> class users(osv.osv):
> _name = 'res.users'
> _inherit = 'res.users'
> _columns = {
> 'period_id': fields.many2one('account.period', 'Period Accounting',
> help='Jail for accounting date entry'),
> }
> users()
>
> causes this error - the period_id s not added.
>
> [2009-11-05 18:00:09,054] INFO:init:module account: creating or updating
> database tables
> [2009-11-05 18:00:09,858] DEBUG:sql:bad query: SELECT
> "menu_id","address_id","period_id","active","context_lang","password","context_tz","name","company_id","signature","login","action_id",id
> FROM "res_users" WHERE id IN (1) ORDER BY id
> [2009-11-05 18:00:09,859] DEBUG:sql:[01]: column "period_id" does not exist
> [2009-11-05 18:00:09,860] DEBUG:sql:[02]: LINE 1: SELECT
> "menu_id","address_id","period_id","active","context_...
> [2009-11-05 18:00:09,860] DEBUG:sql:[03]:
> ^
> Traceback (most recent call last):
> File "./openerp-server.py", line 111, in <module>
> pooler.get_db_and_pool(db, update_module=tools.config['init'] or
> tools.config['update'])
> File "/home/terp/OpenERP/branch/server/5.0/bin/pooler.py", line 40, in
> get_db_and_pool
> addons.load_modules(db, force_demo, status, update_module)
> File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line
> 728, in load_modules
> r = load_module_graph(cr, graph, status, report=report)
> File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line
> 581, in load_module_graph
> init_module_objects(cr, package.name, modules)
> File "/home/terp/OpenERP/branch/server/5.0/bin/addons/__init__.py", line
> 366, in init_module_objects
> result = obj._auto_init(cr, {'module': module_name})
> File "/home/terp/OpenERP/branch/server/5.0/bin/osv/orm.py", line 1875, in
> _auto_init
> default = self._defaults[k](self, cr, 1, {})
> File "/home/terp/OpenERP/branch/server/5.0/bin/addons/account/account.py",
> line 1306...

Read more...

@Jan - good point - I'll do that - I was just thinking about chroot - it's often called jail ....

@Vinay - did try to do so - but one has to take care to export PYTHONPATH to places where all the modules to be imported are located. I never had this problem before.

.../base/res/res_user.py shows
I have never seen "__admin_ids = {}" in another class
might this be the reason prhibiting the change ?

class users(osv.osv):
    __admin_ids = {}
    _name = "res.users"
    #_log_access = False
    _columns = {

Ferdinand (office-chricar) wrote :

solved: after moving
class users(osv.osv):
    _name = 'res.users'
    _inherit = 'res.users'
    _columns = {
         'period_id': fields.many2one('account.period', 'Period Accounting', help='Jail for accounting date entry'),
    }
users()

to a separate file and imorting this as the first in account module - no more error

Ferdinand (office-chricar) wrote :

nevertheless I leave the bug open because
- I do not understand why this pice of code must be placed at the beginning - as it was not used at all
- it should get a better error message if it is really necessary

Hello Ferdinand,

its a problem because, read() of user is called prior to period_id is added as a column to table.

Read is called due to defaults of account_tax.

'period_id' is in ir_model_fields, but not yet into database.

We will sort this out sooner.

Thanks.

Changed in openobject-addons:
status: New → Confirmed
affects: openobject-addons → openobject-server
Ferdinand (office-chricar) wrote :

I still have another problem

res.user needs write permission

to make the period_id enterable.

In res_user.py
    def write(self, cr, uid, ids, values, *args, **argv):
        if (ids == [uid]):
            ok = True
            for k in values.keys():
                if k not in ('password','signature','action_id', 'context_lang', 'context_tz'):
                    ok=False
....
seems to overwrite the permissions ???
I copied this + period_id to my account_user.py but nevertheless the field was not enterable
same is true for document_sftp - the user has no permission to add his keys.

Ferdinand (office-chricar) wrote :

there is onother serious problem
after adding the period field to the accounting module in ONE database it is necessary to update all databases concurrently otherways no login is possible - complains of not finding period_id in the table

serious, because it is unlikely that it is possible to update all databases "at once " so it has to be done one by one and the server must be restarted to make the very database working, whilst making it impossible to login in other databases not having received the update

IMHO the idea was that the server executes the code which lives IN the database for each database, but apparently the code outside the database (from filesystem) is executed for all loaded/installed modules regardless if the db has received the last update.
hope this explains what I mean

Changed in openobject-server:
assignee: nobody → Ysa(Open ERP) (ysa-openerp)

Hi Folks,
Its a limitation of openerp probably. v shud go for another py file in this kind of situation.

Changed in openobject-server:
status: Confirmed → Invalid
Xavier (Open ERP) (xmo) on 2010-01-12
Changed in openobject-server:
status: Invalid → Confirmed
importance: Undecided → Medium
Xavier (Open ERP) (xmo) wrote :

I reopen this bug because I encountered the issue when adding a new field to res.users.

The issue here is that the method _get_company (setting the default value for company) is called before the new columns are created (depending on the ordering of creation, which is arbitrary as it depends on the iteration order of a Python dict), and it performs a browse() on res.users, which forces a read() on all the columns… based on the OpenERP model, which includes columns not-yet created in the DB.

Not only is this a huge problem to create new colums on users (and other objects reading themselves to setup default values), this could break OpenERP if the iteration order of dicts changes with e.g. Python 2.7, or if someone ever manages to make OpenERP run on IronPython or Jython: the field 'menu_id' in 'res.users' is in _columns but not created in base.sql, which means it's generated when created initializing res.users (indeed it is if you check the debug logs of creating a new db) and it just happens that in the iteration order of a Python dict puts 'menu_id' before 'company_id'. If that ever changes, res.users will break hard.

This could (and, in fact, should) be fixed by creating *all* new columns before setting up the default values, then setting up all defaults, and finally applying the constraints (e.g. not null).

sraps (Alistek) (erpsraps) wrote :

I hope that people will pay attentions to this bug...

Here are another strike of it:
http://www.openobject.com/forum/post58571.html#58571

xrg (xrg) wrote :

I would like to play down the importance of this "bug". Some tables like "res.users", "res.company" etc. are supposed to be called nearly at each ORM call, and therefore must be pre-initialized.
Try to avoid adding columns in them, it is also a performance issue.

I remember we have these 'property' fields, couldn't we use them instead, for the functionality you describe?

Note that this bug is mostly mitigated in pg84, by the fact that browse() doesn't fetch all columns by default.

Ferdinand (office-chricar) wrote :

may be we can use res_config_users (which IMHO should be called res_users_config) for such issues.
waht do you think/recommend

Ferdinand (office-chricar) wrote :

and add a (dummy) res_company_config for the same purpose
I have some ideas like
* address label position (in Austria the envelops have the address window on the left side - envelops with the window on the right side are non standard, less choice available and about 30% more expensive)
it could be a seldom used one2one relation

Amit Parik (amit-parik) on 2010-12-24
Changed in openobject-server:
assignee: Ysa(Open ERP) (ysa-openerp) → OpenERP's Framework R&D (openerp-dev-framework)

On Friday 24 December 2010, you wrote:
> ** Changed in: openobject-server
> Assignee: Ysa(Open ERP) (ysa-openerp) => OpenERP's Framework R&D
> (openerp-dev-framework)

Q: why do we consider such an important change for v5.0 (or even v6.0 which is
frozen now) ?

Please, let the framework stay as is. We should queue these things for v6.1
preferably.

Keeping this bugreport in radar for framework improvements after v6.0

summary: - error trying to add column to class users(osv.osv)
+ res.* osv.osv objects may be read() before being fully initialized
Changed in openobject-server:
importance: Medium → Wishlist

Hello Folks,
any notable progress here?
Congratulations by the way, this bug has just completed 3 years last month. we call it 'szczęśliwy dzień urodzenia' in Polish.

P.s. : I will proudly say my son that, you are not the only one I have been involved in the making of! :D

Oops, my bad...it should be 2 years :D

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers