Opened 7 years ago
Closed 7 years ago
#29310 closed Bug (duplicate)
ManyRelatedManager.add() does not accept `bulk` kwarg as described in documentation
Reported by: | Brenton Partridge | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | documentation, orm |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
https://docs.djangoproject.com/en/2.0/ref/models/relations/#django.db.models.fields.related.RelatedManager.add suggests that RelatedManager.add(*objs, bulk=True)
accepts the bulk
kwarg regardless of the type of relationship. However, for many-to-many relationships, https://github.com/django/django/blob/2919a08c20d5ae48e381d6bd251d3b0d400d47d9/django/db/models/fields/related_descriptors.py#L909 does not accept any kwargs. (Master branch as of the submission of this ticket.)
This leads to errors like add() got an unexpected keyword argument ‘bulk’
.
This could be fixed in documentation, since for many-to-many the inserts are going to be bulk regardless. But then RelatedManager wouldn't have a consistent interface across all types of relations. Alternately, we could just add the kwarg to the code and ignore it, and document more clearly that "all many-to-many adds are inserted in bulk, regardless of the choice of bulk kwarg." But we shouldn't just error out on a developer who attempts to follow the documentation.
Any thoughts?
Change History (1)
comment:1 by , 7 years ago
Component: | Database layer (models, ORM) → Documentation |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Duplicate of #29255. A sentence was recently added to the documentation that states that the
bulk
argument doesn't exist for many to many relations.