[Django] #31384: Check if objs are clean before bulk_create, bulk_update

22 views
Skip to first unread message

Django

unread,
Mar 20, 2020, 1:05:22 PM3/20/20
to django-...@googlegroups.com
#31384: Check if objs are clean before bulk_create, bulk_update
-------------------------------------+-------------------------------------
Reporter: GardenLee | Owner: nobody
Type: New | Status: new
feature |
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
We have to check validation of {{{objects set}}} that you want to insert
when trying bulk_create

I suggest Users can do any tasks (ex. model fields validation) through the
parameters like {{{clean_check=True}}} when they use bulk_create and
bulk_update method

I suggest that through the parameters bulk_create, bulk_update method, and
clean_check, when the user wants, the clean function on the object set can
be executed so that the user can perform the desired operation
By implementing this way, users can insert objects only passed by
{{{clean()}}} method that return boolean type
{{{
def bulk_create(self, objs, clean_check=None, batch_size=None,
ignore_conflicts=False):
~~~
if clean_check:
objs = [obj for obj in objs if obj.clean()]
~~~
}}}

By implementing this way, validation errors in clean can prevent the
insertion of object sets containing invalid objects.
{{{
def bulk_create(self, objs, clean_check=None, batch_size=None,
ignore_conflicts=False):
~~~
for obj in objs:
obj.clean()
~~~
}}}

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

Django

unread,
Mar 20, 2020, 1:06:10 PM3/20/20
to django-...@googlegroups.com
#31384: Check if objs are clean before bulk_create, bulk_update
-------------------------------------+-------------------------------------
Reporter: GardenLee | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by GardenLee:

Old description:

> We have to check validation of {{{objects set}}} that you want to insert
> when trying bulk_create
>
> I suggest Users can do any tasks (ex. model fields validation) through
> the parameters like {{{clean_check=True}}} when they use bulk_create and
> bulk_update method
>
> I suggest that through the parameters bulk_create, bulk_update method,
> and clean_check, when the user wants, the clean function on the object
> set can be executed so that the user can perform the desired operation
> By implementing this way, users can insert objects only passed by
> {{{clean()}}} method that return boolean type
> {{{
> def bulk_create(self, objs, clean_check=None, batch_size=None,
> ignore_conflicts=False):
> ~~~
> if clean_check:
> objs = [obj for obj in objs if obj.clean()]
> ~~~
> }}}
>
> By implementing this way, validation errors in clean can prevent the
> insertion of object sets containing invalid objects.
> {{{
> def bulk_create(self, objs, clean_check=None, batch_size=None,
> ignore_conflicts=False):
> ~~~
> for obj in objs:
> obj.clean()
> ~~~
> }}}

New description:

--

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

Django

unread,
Mar 20, 2020, 1:12:15 PM3/20/20
to django-...@googlegroups.com
#31384: Check if objs are clean before bulk_create, bulk_update
-------------------------------------+-------------------------------------
Reporter: GardenLee | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

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


Comment:

Model validation and persistence are separated concerns.

For example `Model.save()` doesn't invoke `.clean()` so I don't think
`bulk_create` should differ from that.

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

Reply all
Reply to author
Forward
0 new messages