[Django] #31551: TypeError: _bulk_create() got an unexpected keyword argument 'ignore_conflicts'

52 views
Skip to first unread message

Django

unread,
May 8, 2020, 10:56:28 AM5/8/20
to django-...@googlegroups.com
#31551: TypeError: _bulk_create() got an unexpected keyword argument
'ignore_conflicts'
-------------------------------------+-------------------------------------
Reporter: scshivam | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords: Many-to-many Fields
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Code:

I get error in using .add() and .set() functions with many to many keys in
models.
I rolled back to Django-2.2.12 and this issue was gone.

{{{
class GroupSerializer(serializers.ModelSerializer):
permissions = PermissionSerializerGroup(many=True, required=False)

class Meta:
model = Group
fields = ('id', 'name', 'permissions')
extra_kwargs = {
'name': {'validators': []},
}

def create(self, validated_data):
print(validated_data)
permissions_data = validated_data.pop("permissions")
obj, group =
Group.objects.update_or_create(name=validated_data["name"])
obj.permissions.clear()
for permission in permissions_data:
per = Permission.objects.get(codename=permission["codename"])
obj.permissions.add(per)
obj.save()
return obj
}}}


Traceback:
{{{
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/options.py", line 607, in wrapper
return self.admin_site.admin_view(view)(*args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/sites.py", line 231, in inner
return view(request, *args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/options.py", line 1638, in add_view
return self.changeform_view(request, None, form_url, extra_context)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/utils/decorators.py", line 130, in _wrapped_view
response = view_func(request, *args, **kwargs)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/options.py", line 1522, in changeform_view
return self._changeform_view(request, object_id, form_url,
extra_context)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/options.py", line 1566, in _changeform_view
self.save_related(request, form, formsets, not add)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/contrib/admin/options.py", line 1107, in save_related
form.save_m2m()
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/forms/models.py", line 442, in _save_m2m
f.save_form_data(self.instance, cleaned_data[f.name])
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/db/models/fields/related.py", line 1618, in save_form_data
getattr(instance, self.attname).set(data)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/db/models/fields/related_descriptors.py", line 1008, in
set
self.add(*new_objs, through_defaults=through_defaults)
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/db/models/fields/related_descriptors.py", line 946, in add
through_defaults=through_defaults,
File "/home/suman/Desktop/suman1234/myvenv/lib/python3.6/site-
packages/django/db/models/fields/related_descriptors.py", line 1129, in
_add_items
], ignore_conflicts=True)
TypeError: _bulk_create() got an unexpected keyword argument
'ignore_conflicts'
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31551>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 8, 2020, 2:25:27 PM5/8/20
to django-...@googlegroups.com
#31551: TypeError: _bulk_create() got an unexpected keyword argument
'ignore_conflicts'.
-------------------------------------+-------------------------------------
Reporter: Shivam Chaurasia | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: needsinfo

Keywords: Many-to-many Fields | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: new => closed
* resolution: => needsinfo


Comment:

Thanks for this ticket, however I cannot reproduce this issue, moreover
`_bulk_create()` (with leading underscore) never existed in the Django.
Can you provide a sample project to reproduce this issue?

--
Ticket URL: <https://code.djangoproject.com/ticket/31551#comment:1>

Django

unread,
Oct 24, 2020, 11:03:55 AM10/24/20
to django-...@googlegroups.com
#31551: TypeError: _bulk_create() got an unexpected keyword argument
'ignore_conflicts'.
-------------------------------------+-------------------------------------
Reporter: Shivam Chaurasia | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.1

(models, ORM) |
Severity: Normal | Resolution:
Keywords: Many-to-many Fields | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Ethan Meanor):

* status: closed => new
* version: 3.0 => 3.1
* resolution: needsinfo =>


Comment:

I am having the same issue in 3.1. This happens when calling .add() both
from Django project files and from the shell. You should be able to
reproduce it in this project:
https://github.com/emeanor/wtp/

Specifically, the error is being generated in /texts/tests.py, by the
function {{{test_can_be_attached_to_multiple_divisions}}} (currently
commented out):
https://github.com/emeanor/wtp/blob/main/texts/tests.py

{{{
def test_can_be_attached_to_multiple_divisions(self):
edition = Edition.objects.create()
divisions = [Division.objects.create(edition=edition) for i in
range(3)]

for division in divisions:
division.texts.add(self.text) # .add() is the error source.

self.assertEquals(len(divisions), self.text.division_set.count())

for division in divisions:
self.assertIn(division, self.text.division_set)
}}}


Trackeback:

{{{
Traceback (most recent call last):
File "/home/ethan/dev/projects/wtp/texts/tests.py", line 41, in
test_can_be_attached_to_multiple_divisions
division.texts.add(self.text)
File "/home/ethan/dev/.venv/wtp/lib/python3.8/site-
packages/django/db/models/fields/related_descriptors.py", line 950, in add
self._add_items(
File "/home/ethan/dev/.venv/wtp/lib/python3.8/site-
packages/django/db/models/fields/related_descriptors.py", line 1150, in
_add_items
self.through._default_manager.using(db).bulk_create([
TypeError: bulk_create() got an unexpected keyword argument
'ignore_conflicts'
}}}

Note that {{{bulk_create()}}} here does not have the leading underscore.

--
Ticket URL: <https://code.djangoproject.com/ticket/31551#comment:2>

Django

unread,
Oct 24, 2020, 12:07:54 PM10/24/20
to django-...@googlegroups.com
#31551: TypeError: _bulk_create() got an unexpected keyword argument
'ignore_conflicts'.
-------------------------------------+-------------------------------------
Reporter: Shivam Chaurasia | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: Many-to-many Fields | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed

* resolution: => invalid


Comment:

That looks like an issue with
[https://github.com/bfirsh/django-ordered-model/pull/228 django-ordered-
model]. When providing steps to reproduce an issue, try to remove all
third-party dependencies to rule out a bug there.

--
Ticket URL: <https://code.djangoproject.com/ticket/31551#comment:3>

Reply all
Reply to author
Forward
0 new messages