0

I am running the following code segment to print a jasper report in OpenERP

prev_open_fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft'), ('date_start', '<', fiscal_date_start)]) # prev_open_fiscalyear_ids gets a list of numbers from this code
cr.execute("SELECT id \
                        FROM account_period \
                        WHERE fiscalyear_id IN %s" , (tuple(prev_open_fiscalyear_ids)))
prev_period_ids = filter(None, map(lambda x:x[0], cr.fetchall()))

where cr is the database cursor to PostgreSQL db and I am getting the following error:

Report Error from Client

and the server log is

[2014-08-06 10:27:47,625][ASCO_ERP] ERROR:web-services:[01]: Exception: not all arguments converted during string formatting
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[02]: Traceback (most recent call last):
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[03]:   File "/home/zbeanz/workspace/KIAK/service/web_services.py", line 724, in go
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[04]:     (result, format) = obj.create(cr, uid, ids, datas, context)
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[05]:   File "/home/zbeanz/workspace/KIAK/addons/jasper_reports/jasper_report.py", line 287, in create
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[06]:     data['records'] = d.get( 'records', [] )
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[07]:   File "/home/zbeanz/workspace/KIAK/addons/kiak_tb_report/JasperDataParser.py", line 53, in get
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[08]:     self.generate_records(self.cr, self.uid, self.ids, self.data, self.context) or default_value
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[09]:   File "/home/zbeanz/workspace/KIAK/addons/kiak_tb_report/report/trial_balance_report.py", line 149, in generate_records
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[10]:     WHERE fiscalyear_id IN %s" % (tuple(prev_open_fiscalyear_ids)))
[2014-08-06 10:27:47,626][ASCO_ERP] ERROR:web-services:[11]: TypeError: not all arguments converted during string formatting

What is the problem associated with the query

4
  • 2
    Is it possible that the search query doesn't return any results such that tuple(prev_open_fiscalyear_ids)) is just an empty tuple? Commented Aug 6, 2014 at 5:12
  • 1
    Yes, the result is fetched in the next line from the DB cursor as prev_period_ids = filter(None, map(lambda x:x[0], cr.fetchall())) Commented Aug 6, 2014 at 5:14
  • 1
    How about (tuple(prev_open_fiscalyear_ids),) (notice the comma), does that help? Commented Aug 6, 2014 at 5:22
  • 1
    @bereal yes, the comma solved the problem. If you put it as an answer I can accept the answer Commented Aug 6, 2014 at 5:27

1 Answer 1

2

Currently tuple(prev_open_fiscalyear_ids) is interpreted as a list of arguments to substitute in the query. That's not what you mean, you want your tuple to be a replacement for the single argument:

cr.execute(query, (tuple(prev_open_fiscalyear_ids),))

Unless I'm missing something, this should work too:

cr.execute(query, (prev_open_fiscalyear_ids,))

The comma in the end is because (x) is always the same as x, while (x,) is a tuple with the single element.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.