Opened 15 years ago

Closed 15 years ago

Last modified 12 years ago

#10438 closed (fixed)

Rowcount for updates not correct with MySQL

Reported by: Malcolm Tredinnick Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Malcolm Tredinnick)

With the MySQL backend, the model_inheritance_regress tests currently fail because the rowcount returned from django.db.models.sql.subqueries.UpdateQuery.execute_sql() is wrong. This is only in the special case introduced in r9967. I don't understand why, yet.

Attachments (1)

mysql_rows.patch (931 bytes ) - added by Daniel Tang <dytang@…> 15 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 by Malcolm Tredinnick, 15 years ago

Description: modified (diff)

comment:2 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Malcolm Tredinnick, 15 years ago

milestone: 1.1

The issue at hand here is that MySQL returns the number of rows changed by an update, not the number of rows that were attempted to be updated, as the other databases do. We need to work around this somehow, as it's necessary to detect whether Model.save(force_update=True) worked or not.

Possibly needs another MySQL-specific workaround to select the number of rows that might have been affected (a little racy, but that might just be the way it goes).

by Daniel Tang <dytang@…>, 15 years ago

Attachment: mysql_rows.patch added

comment:4 by Daniel Tang <dytang@…>, 15 years ago

Has patch: set

Also sent to django-developers:

Not sure if this is an end-all solution, but you can pass a client_flag kwarg that makes MySQLdb return the number of matched rows instead of affected rows. In MySQLdb.constants.CLIENT there is a FOUND_ROWS constant. Passing it to connect resolves this problem. Patch attached just to show what I did.

comment:5 by Malcolm Tredinnick, 15 years ago

Resolution: fixed
Status: newclosed

(In [10532]) Fixed #10438 -- Fixed MySQL backend behaviour for UPDATE behaviour.

We need to know the number of rows that are matched by an UPDATE query,
not just the number of rows that are changed. In the relatively unlikely
event that somebody was using Django's cursor proxy and relying on the
previous behaviour, well, that isn't the case any longer. We need to
this version.

Thanks to Daniel Tang for pointing out the solution here.

comment:6 by Malcolm Tredinnick, 15 years ago

(In [10533]) [1.0.X] Fixed #10438 -- Fixed MySQL backend behaviour for UPDATE behaviour.

We need to know the number of rows that are matched by an UPDATE query,
not just the number of rows that are changed. In the relatively unlikely
event that somebody was using Django's cursor proxy and relying on the
previous behaviour, well, that isn't the case any longer. We need to
this version.

Thanks to Daniel Tang for pointing out the solution here.

Backport of r10532 from trunk.

comment:7 by Jacob, 12 years ago

milestone: 1.1

Milestone 1.1 deleted

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