Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper.bulk_update seems to fail when only one pk #31

Closed
serguitus opened this issue Sep 9, 2015 · 3 comments
Closed

helper.bulk_update seems to fail when only one pk #31

serguitus opened this issue Sep 9, 2015 · 3 comments

Comments

@serguitus
Copy link

At ./helper.pyL#63 paramaters contains a tuple of ids for the WHERE condition (WHERE pk in (val1, val2))
when there is only one item to update then the resulting sql ends in WHERE pk in (val1,) so I get
(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1")
I know that if I'm not going to update only one object, then I should not use bulk_update but, shouldn't this be capable of handling also a list of only 1 item? or at list handle the error :-)
A code like this on ./helper.pyL#57 fixed the issue for me

   if len(pks) > 1:
                paramaters.extend([tuple(pks)])
                sql = 'UPDATE {dbtable} SET {values} WHERE {pkcolumn} in %s'\
                    .format(dbtable=dbtable, values=values, pkcolumn=pkcolumn)
            else:
                paramaters.extend(pks)
                sql = 'UPDATE {dbtable} SET {values} WHERE {pkcolumn} in (%s)'\
                    .format(dbtable=dbtable, values=values, pkcolumn=pkcolumn) 

I don't know if you like the idea. If you do, then I could do a PR for you
Thanks for this nice tool

@aykut
Copy link
Owner

aykut commented Sep 10, 2015

Hi,
You are certainly right that it must also handle lists with one item. It is clearly a bug.

I'll investigate and make a patch as soon as possible.

Thanks.

aykut added a commit that referenced this issue Jan 28, 2016
@aykut
Copy link
Owner

aykut commented Jan 28, 2016

Hi,
It seems ok with mysql as I just created a test case for this situation. Are you still having the problem.

Thanks.

@serguitus
Copy link
Author

I will try and get back to you

On 27/01/16 19:06, Aykut Özat wrote:

Hi,
It seems ok with mysql as I just created a test case for this
situation. Are you still having the problem.

Thanks.


Reply to this email directly or view it on GitHub
#31 (comment).

@aykut aykut closed this as completed Apr 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants