Opened 7 months ago

Closed 6 months ago

#21205 closed Bug (duplicate)

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

Reported by: NiGhTTraX Owned by: nobody
Component: Database layer (models, ORM) Version: master
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.

Attachments (0)

Change History (3)

comment:1 Changed 6 months ago by foobarbecue

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Isn't this a duplicate of #16426?

comment:2 Changed 6 months ago by NiGhTTraX

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 6 months ago by aaugustin

  • Resolution set to duplicate
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.