Opened 4 years ago

Closed 4 years ago

#31384 closed New feature (wontfix)

Check if objs are clean before bulk_create, bulk_update

Reported by: GardenLee Owned by: nobody
Component: Database layer (models, ORM) Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by GardenLee)

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()
        ~~~

Change History (2)

comment:1 by GardenLee, 4 years ago

Description: modified (diff)

comment:2 by Simon Charette, 4 years ago

Resolution: wontfix
Status: newclosed

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.

Note: See TracTickets for help on using tickets.
Back to Top