Opened 9 years ago

Closed 9 years ago

#21205 closed Bug (duplicate)

related_objects() fails on SQLite when passing more than 999 objects

Reported by: Andrei Picus Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords: sqlite delete related 999
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Using SQLite, trying to delete objects that have more than 999 related objects will fail with a 'too many SQL variables' error. This is due to the related_objects() method getting all the related objects in one query.

I've written a patch to fetch the related objects in batches using the bulk_batch_size database ops. You can check it here:

Also added a new test to check for this new behavior.

All comments are welcome.

Change History (3)

comment:1 Changed 9 years ago by foobarbecue

Isn't this a duplicate of #16426?

comment:2 Changed 9 years ago by Andrei Picus

Seems like it. But, looking at the proposed patch, I see that it doesn't use the max_batch_size database ops.

Also, the splitting occurs at the collect() level, while I propose that it happens in related_objects(), as that's where the problem lies.

Feel free to discuss both patches.

I think this should be fixed as soon as possible since it could break a lot of people's code, especially when trying to truncate tables via objects.all().delete().

comment:3 Changed 9 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed

Let's keep the discussion in a single place; I'm marking this ticket as a duplicate of #16426.

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