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

django-pyodbc bulk_create is broken #132

Open
aergener opened this issue Dec 7, 2016 · 4 comments
Open

django-pyodbc bulk_create is broken #132

aergener opened this issue Dec 7, 2016 · 4 comments

Comments

@aergener
Copy link

aergener commented Dec 7, 2016

I posted this on stackoverflow: http://stackoverflow.com/questions/41025790/django-pyodbc-bulk-create-is-broken

When calling bulk_create() using django-pyodbc backend, an insert statement is run for each object in the batch. The behavior should be to run a single insert statement per batch.

Is this a bug, or is there a way to alter this behavior?

Versions:

django==1.7
pyodbc==3.0.10
django-pyodbc==1.0.1
FreeTDS v1.00.21
unixODBC v2.3.4

@RossRogers
Copy link
Contributor

RossRogers commented Dec 7, 2016 via email

@aergener
Copy link
Author

aergener commented Dec 7, 2016

Working on one right now that I'll post here. But basically anytime a model calls bulk_create I see that behavior.

@aergener
Copy link
Author

aergener commented Dec 8, 2016

With the following model:

from django.db import models

class Thing(models.Model):
    prop = models.CharField(max_length=64)

Execute the following below from the django shell:

>>> from app.models import *
>>> thing1 = Thing(prop='hello')
>>> thing2 = Thing(prop='world')
>>> things = [thing1, thing2]
>>> Thing.objects.bulk_create(things)
[<Thing: Thing object>, <Thing: Thing object>]

If you enable logging, you'll see that a SQL INSERT statement is executed for each item in the bulk_create batch.

@aergener
Copy link
Author

aergener commented Dec 8, 2016

I also have an example setup here https://github.com/aergener/django-mssql-setup-example

It uses docker so as long as you have Docker installed, you'll be able to launch the exact same setup. There's also a vagrantfile there if you have vagrant and want it to provision a machine for you with Docker.

Currently that setup is using django-pyodbc-azure, but if you update the database settings & the requirements.txt to the following you should see what I am seeing.

requirements.txt

django==1.7
pyodbc==3.0.10
django-pyodbc==1.0.1

@dlo dlo added the help wanted label Feb 1, 2018
@dlo dlo added the bug label Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants