Comment 1 for bug 327120

Revision history for this message
paulkoan (c-launchpad-airbred-com) wrote :

Thanks for the quick response - this didn't actually fix it though. With the same data, the error is the same, but the id list is now split so that each id has a comma inserted between the first and second digit of the id:

ProgrammingError: invalid input syntax for integer: "3,43,33,52,92,12,21,2"

(should be: "34,33,35,29,21,22,12")

The original error is reported later on, as the query is passed to the object, and it looks correct - if you took it straight to SQL it would be managed fine:

SELECT * FROM account_analytic_line WHERE account_id = 2 and id IN (34,33,35,29,21,22,12) AND product_id=3 and to_invoice=1

I think the problem is that the query parameter gets quoted:

SELECT * FROM account_analytic_line WHERE account_id = 2 and id IN ('3,43,33,52,92,12,21,2') AND product_id=3 and to_invoice=1

(ignoring that the fix has caused the id list to be created incorrectly).

I think the problem must be further along, perhaps in the cursor code itself - it is quoting input perhaps where it shouldn't, perhaps as an injection protection mechanism?

If I de-parameterise it:

                str_ids=','.join(map(str,data['ids']))
# for x in data['ids']:
# str_ids += ','.join(str(x))
                cr.execute("SELECT * FROM account_analytic_line WHERE account_id = %s and id IN ("+str_ids+") AND product_id=%s and to_invoice=%s", (account.id, product_id, factor_id))

The invoice gets created (though without any pricing, which I suspect is a different problem).