← Back to team overview

c2c-oerpscenario team mailing list archive

Re: [Bug 802352] Re: [6.0] Inheriting _constraints "list index out of range" if original len(_constraint ) is bigger than the new one

 

Hello Vinay.

Try to inherit exactly the model that i putted on the description in bug,
this is a good example, the model 'stock.move' originally has 2 constraints,
i put on my inheritance one more (less than the original one), if you see
the original code, you can see that the server is itering between the
original, but the inherited is not itered it is just called, with this the
server is considering just one case....

I attach one db before install module:
#DATABASE INFO
db_password = 123
list_db = True
db_port = False
db_name = False
db_user = guadalajara
db_host = False


the branch (there are a module just presenting this issue, ) try to install
this module.

BRANCH: lp:~openerp-commiter/openobject-server/constrain_Bug_802352

Regards.


2011/6/27 Vinay Rana (openerp) <802352@xxxxxxxxxxxxxxxxxx>

> Hello Nhomar,
>
> I have checked similar issue with latest stable and trunk code but did not
> face any traceback while updating the exiting db.
> Would you please provide me more steps to reproduce the same traceback at
> my end.
>
> Thanks.
>
> ** Changed in: openobject-server
>       Status: New => Incomplete
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/802352
>
> Title:
>  [6.0] Inheriting _constraints "list index out of range" if original
>  len(_constraint ) is bigger than the new one
>
> Status in OpenERP Server:
>   Incomplete
>
> Bug description:
>  branch: 6.0
>  addons : 4677
>  server: 3452
>  My module example:
>  class stock_move_constraint(osv.osv):
>      _inherit = 'stock.move'
>      _columns = {}
>      def _check_import_info(self, cr, uid, ids, context=None):
>          print "I checked"
>          return True
>      _constraints = [
>          (_check_import_info,'You must assign a track lot with import
> information for this product',['tracking_id'])],
>  stock_move_constraint()
>
>  When I try to update my module ($python openerp-server.py -u mymodule
>  -d mydb) this traceback is received.
>
>  Traceback (most recent call last):
>    File "./openerp-server.py", line 121, in <module>
>      db,pool = pooler.get_db_and_pool(dbname,
> update_module=tools.config['init'] or tools.config['update'],
> pooljobs=False)
>    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/pooler.py",
> line 39, in get_db_and_pool
>      addons.load_modules(db, force_demo, status, update_module)
>    File
> "/home/nhomar/CD_curso/linux_and_sources/server/bin/addons/__init__.py",
> line 883, in load_modules
>      processed_modules.extend(load_module_graph(cr, graph, status,
> report=report, skip_modules=processed_modules))
>    File
> "/home/nhomar/CD_curso/linux_and_sources/server/bin/addons/__init__.py",
> line 717, in load_module_graph
>      modules = pool.instanciate(package.name, cr)
>    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/osv/osv.py",
> line 258, in instanciate
>      res.append(klass.createInstance(self, module, cr))
>    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/osv/osv.py",
> line 354, in createInstance
>      if new[c2][2]==c[2] and (new[c2][0] == c[0] \
>  IndexError: list index out of range
>
>  I printed variables of this method (check patch it is corrected) and
>  some kind of bad logic is used, the server is trying to check as a
>  list an integer....
>
>  Original problem
>  ~~~~LINE 348 on osv.py
>
>                          if s=='_constraints':
>                              for c in cls.__dict__.get(s, []):
>                                  exist = False
>                                  for c2 in range(len(new)):
>   ####THIS IS MY PRINT it is an integer,,,,,
>  #on the range(len(new)) always will return an index in c2 of the original
> class never, and if the original
>  #_constraint list in class is bigger than the new one it will broke.
>                                       print c2
>                                       #For _constraints, we should check
> field and methods as well
>                                       if new[c2][2]==c[2] and (new[c2][0]
> == c[0] \
>                                              or
> getattr(new[c2][0],'__name__', True) == \
>                                                  getattr(c[0],'__name__',
> False)):
>                                          # If new class defines a
> constraint with
>                                          # same function name, we let it
> override
>                                          # the old one.
>                                          new[c2] = c
>                                          exist = True
>                                          break
>                                  if not exist:
>                                      new.append(c)
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/openobject-server/+bug/802352/+subscriptions
>


-- 
Saludos Cordiales

Nhomar G. Hernandez M.
+58-414-4110269
Skype: nhomar00
Web-Blog: http://geronimo.com.ve
Servicios IT: http://openerp.com.ve
Linux-Counter: 467724
Correos:
nhomar@xxxxxxxxxxxxxx <nhomar.hernandez@xxxxxxxxxxxxx>
nhomar@xxxxxxxxxxxxxxx
twitter: @nhomar

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/802352

Title:
  [6.0] Inheriting _constraints "list index out of range" if original
  len(_constraint ) is bigger than the new one

Status in OpenERP Server:
  In Progress

Bug description:
  branch: 6.0
  addons : 4677
  server: 3452
  My module example:
  class stock_move_constraint(osv.osv):   
      _inherit = 'stock.move'
      _columns = {}
      def _check_import_info(self, cr, uid, ids, context=None):
          print "I checked"
          return True
      _constraints = [
          (_check_import_info,'You must assign a track lot with import information for this product',['tracking_id'])],
  stock_move_constraint()

  When I try to update my module ($python openerp-server.py -u mymodule
  -d mydb) this traceback is received.

  Traceback (most recent call last):
    File "./openerp-server.py", line 121, in <module>
      db,pool = pooler.get_db_and_pool(dbname, update_module=tools.config['init'] or tools.config['update'], pooljobs=False)
    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/pooler.py", line 39, in get_db_and_pool
      addons.load_modules(db, force_demo, status, update_module)
    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/addons/__init__.py", line 883, in load_modules
      processed_modules.extend(load_module_graph(cr, graph, status, report=report, skip_modules=processed_modules))
    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/addons/__init__.py", line 717, in load_module_graph
      modules = pool.instanciate(package.name, cr)
    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/osv/osv.py", line 258, in instanciate
      res.append(klass.createInstance(self, module, cr))
    File "/home/nhomar/CD_curso/linux_and_sources/server/bin/osv/osv.py", line 354, in createInstance
      if new[c2][2]==c[2] and (new[c2][0] == c[0] \
  IndexError: list index out of range

  I printed variables of this method (check patch it is corrected) and
  some kind of bad logic is used, the server is trying to check as a
  list an integer....

  Original problem
  ~~~~LINE 348 on osv.py

                          if s=='_constraints':
                              for c in cls.__dict__.get(s, []):
                                  exist = False
                                  for c2 in range(len(new)):
   ####THIS IS MY PRINT it is an integer,,,,, 
  #on the range(len(new)) always will return an index in c2 of the original class never, and if the original 
  #_constraint list in class is bigger than the new one it will broke.
                                       print c2 
                                       #For _constraints, we should check field and methods as well
                                       if new[c2][2]==c[2] and (new[c2][0] == c[0] \
                                              or getattr(new[c2][0],'__name__', True) == \
                                                  getattr(c[0],'__name__', False)):
                                          # If new class defines a constraint with
                                          # same function name, we let it override
                                          # the old one.
                                          new[c2] = c
                                          exist = True
                                          break
                                  if not exist:
                                      new.append(c)

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/802352/+subscriptions


References