Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10438 closed (fixed)

Rowcount for updates not correct with MySQL

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

Description (last modified by mtredinnick)

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@…> 5 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 5 years ago by mtredinnick

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by Alex

  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 5 years ago by mtredinnick

  • milestone set to 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).

Changed 5 years ago by Daniel Tang <dytang@…>

comment:4 Changed 5 years ago by Daniel Tang <dytang@…>

  • 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 Changed 5 years ago by mtredinnick

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

(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 Changed 5 years ago by mtredinnick

(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 Changed 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

Add Comment

Modify Ticket

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


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

 
Note: See TracTickets for help on using tickets.