Skip to content

Commit

Permalink
[1.9.x] Fixed #22705 -- Fixed QuerySet.bulk_create() on models withou…
Browse files Browse the repository at this point in the history
…t any fields on Oracle.

Fixed on other backends by 134ca4d.

Thanks Mariusz Felisiak for the solution.

Backport of 7a5b7e3 from master
  • Loading branch information
timgraham committed Oct 9, 2015
1 parent f717cb2 commit 7cd2995
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions django/db/backends/oracle/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ def max_in_list_size(self):
def max_name_length(self):
return 30

def pk_default_value(self):
return "NULL"

def prep_for_iexact_query(self, x):
return x

Expand Down
4 changes: 4 additions & 0 deletions tests/bulk_create/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@ class State(models.Model):
class TwoFields(models.Model):
f1 = models.IntegerField(unique=True)
f2 = models.IntegerField(unique=True)


class NoFields(models.Model):
pass
8 changes: 6 additions & 2 deletions tests/bulk_create/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
)

from .models import (
Country, Pizzeria, ProxyCountry, ProxyMultiCountry, ProxyMultiProxyCountry,
ProxyProxyCountry, Restaurant, State, TwoFields,
Country, NoFields, Pizzeria, ProxyCountry, ProxyMultiCountry,
ProxyMultiProxyCountry, ProxyProxyCountry, Restaurant, State, TwoFields,
)


Expand Down Expand Up @@ -177,6 +177,10 @@ def test_explicit_batch_size(self):
TwoFields.objects.bulk_create(objs, len(objs))
self.assertEqual(TwoFields.objects.count(), len(objs))

def test_empty_model(self):
NoFields.objects.bulk_create([NoFields() for i in range(2)])
self.assertEqual(NoFields.objects.count(), 2)

@skipUnlessDBFeature('has_bulk_insert')
def test_explicit_batch_size_efficiency(self):
objs = [TwoFields(f1=i, f2=i) for i in range(0, 100)]
Expand Down

0 comments on commit 7cd2995

Please sign in to comment.