#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

Description

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:
https://github.com/django/django/pull/1699

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

All comments are welcome.

Change History (3)

comment:1 Changed 21 months ago by foobarbecue

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

Isn't this a duplicate of #16426?

comment:2 Changed 21 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 21 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.

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