← Back to team overview

c2c-oerpscenario team mailing list archive

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

 

@xrg

When somebody do his work well , this kind of thing happens.... THANKS a
lot xrg you are the man ;-)


I propose one thing, this thing took from me at least 4 hours i think i can not be the only one that can have this "finger error", i propose for trunk merge the diff attached it verifiy that the typo is correct when you inherit a _constraint.

I don't know if the place for this verification is right but i propose
the idea....

Thanks a Lot again GREAT WORK guys.

PD:

When you say ...
Lesson learned: do not mix Java into Python. Have your code lines fit in a single screen width ! (careful with those commas, too)

Je... I'm not Java developer, it was an "finger error", please, don't
call me java developer, i feel bad enought for my error jejej!

** Patch added: "constraint"
   https://bugs.launchpad.net/openobject-server/+bug/802352/+attachment/2183100/+files/diff_error_controled.diff

** Changed in: openobject-server
       Status: Invalid => Opinion

-- 
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:
  Opinion

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


Follow ups

References