Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#12656 closed Uncategorized (worksforme)

QuerySet.defer in default Manager breaks batch update (w/mysql?)

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


I have an object with a large, infrequently used textfield. I created a manager that defers that field since I do generate pages where I retrieve hundreds of those objects and I didn't want to spread defer() around everywhere.

This seems to break qs.update(). I have a ModelAdmin class that adds an option to globally set/unset a boolean. When I invoke it on the class with the modified manager I get mysql syntax error:

(1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM coverage_coverage U0 INNER JOIN coverage_run U1 ON (U0.run_id = U1.`i' at line 1")

Strangely this only happens if I first do a search from the admin interface and select from the search result. The code appears to simply do 'id in selected' so I'm not sure why the prior search would matter.

If this does not leap out as an 'aha' for someone I can try to distill a minimal case.

(version 1.1.1)

Change History (2)

comment:1 Changed 9 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed

I don't doubt you are seeing a problem, but without any substantive details of the models or query that is failing, there isn't much we can do to help.

Django has a fairly extensive test suite, and defer() is tested in that test suite. The abstract description of 'using defer on a textfield in MySQL' doesn't help us narrow down a problem. Distilling a reproducible test case is not an optional step.

Marking worksforme, because the test suite says defer works fine; if you care to provide a reproducible test case, feel free to reopen.

comment:2 Changed 7 years ago by anonymous

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

The way I workarounded this bug:

#In the action function
def do_something(self, request, queryset):

id_list = list(queryset.values_list('id', flat=True))
rows_updated = MyModel.objects.filter(idin=id_list)
#Your update goes here
rows_updated = rows_updated.update(field=True)

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