1

I'm using the prestashop - openerp connector module, but when i try to import data from the website is giving me this error traceback:

  File "/usr/prestaconnect/openerp-connector/connector/queue/worker.py", line 122, in run_job
job.perform(session)
  File "/usr/prestaconnect/openerp-connector/connector/queue/job.py", line 460, in perform
self.result = self.func(session, *self.args, **self.kwargs)
  File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 663, in import_batch
importer.run(filters=filters, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 202, in run
return super(PaymentMethodsImportSynchronizer, self).run(filters, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 176, in run
record_ids = self._run_page(filters)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 186, in _run_page
self._import_record(record_id, **kwargs)
 File "/usr/prestaconnect/prestashoperpconnect/prestashoperpconnect/unit/import_synchronizer.py", line 206, in _import_record
('name', '=', record['payment']),
TypeError: string indices must be integers, not str

In the module code i see this:

 class PaymentMethodsImportSynchronizer(BatchImportSynchronizer):
_model_name = 'payment.method'

def run(self, filters=None, **kwargs):
    if filters is None:
        filters = {}
    filters['display'] = '[id,payment]'
    return super(PaymentMethodsImportSynchronizer, self).run(filters, **kwargs)

def _import_record(self, record):
    ids = self.session.search('payment.method', [
        ('name', '=', record['payment']),
        ('company_id', '=', self.backend_record.company_id.id),
    ])
    if ids:
        return
    self.session.create('payment.method', {
        'name': record['payment'],
        'company_id': self.backend_record.company_id.id,
    })

I don't know what actually is happening, i need some lights on this, cause i did not developed this module, and i'm new to prestashop - openerp integration.

Any help would be greatly appreciated, thanks in advance!

NeoVe
  • 3,857
  • 8
  • 54
  • 134

1 Answers1

1

Your traceback tells you exactly what you need to know.

It looks like you are passing a string to _import_record instead of a dict. Why don't you check to see what record is.

The easiest way to debug what is happening is to use pdb the Python debugger. Just inside the _import_record function, above the ids = ... put, import pdb; pdb.set_trace(). Then run the program as usual, pdb will break at that line and then you can analyse what record is set to.

See: http://pythonconquerstheuniverse.wordpress.com/2009/09/10/debugging-in-python/ or Getting started with the Python Debugger pdb an intro to pdb and debugging with Python in general. You will need this skill if you are working with code you haven't written yourself.

Community
  • 1
  • 1
William Denman
  • 3,046
  • 32
  • 34
  • If you are trying to debug other peoples code or understand third party modules, you should use the python debugger `pdb` – William Denman Nov 29 '13 at 23:45
  • Hi, i'm using pdb right now, still no clue, i'm going to keep testing and write you back. – NeoVe Dec 02 '13 at 17:12
  • What did the `record` that was being passed to `_import_record()` end up holding? – William Denman Dec 02 '13 at 17:26
  • Problem is giving me an error because of dependencies, i mean, it doesn't find a module which is part of the 'openerp module' itself, when running it on pdb in python – NeoVe Dec 02 '13 at 18:29
  • can't execute it :(, any ideas to debug it? – NeoVe Dec 02 '13 at 18:29
  • I mean, if i execute it, and let's say i comment the missing imports, then obviously throws more errors due to the fact that isn't importing the other modules i commented in order to run the program on pdb – NeoVe Dec 02 '13 at 18:34
  • Hmm. Can you tell me how you are using pdb? You don't `run` a program on pdb. See my updated answer. – William Denman Dec 03 '13 at 11:05
  • Thank you very much, but yes i'm using it the standard way, i mean in code.py, in imports section, import pdb, then in first class i add pdb.set_trace(), as usual, but i have to comment some other imports in order to run it with sudo python code.py (i'm on ubuntu), because if i don't do, then the code.py won't run, because is part of other codes, or modules in openerp. And in that case, obviously throws more errors due to the fact that isn't importing the openerp modules. It's running on it's own. – NeoVe Dec 03 '13 at 15:09
  • And of course i use the 'n' to go through methods, but there's a point when it throws an undefined method, that is actually defined in another module it imports, it is an error caused by myself, by commenting the imports that doesn't let me to run the program (code.py). So i can't figure out what the actual error is, the record one for saying. – NeoVe Dec 03 '13 at 15:16
  • Really? Well, thx but i don't think it will make a difference, i can try anyway... – NeoVe Dec 03 '13 at 15:24
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/42422/discussion-between-william-denman-and-neove) – William Denman Dec 03 '13 at 16:07
  • Agreed:) leaved you some message on chat – NeoVe Dec 03 '13 at 19:49