Code

Opened 3 months ago

Closed 3 months ago

#21761 closed Uncategorized (invalid)

Confused about "Forced update did not affect any rows."

Reported by: jeroen.pulles@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a DatabaseError("Forced update did not affect any rows.") (from model.save_base).

I cannot reproduce the error; Manually running save(force_update) on not-really-changed objects of the same type in a Django shell doesn't raise this exception.

What does this exception apply to?

I am under the impression that the model.save() force_insert/force_update arguments are there to get control over database operations. And as such I was expecting that force_update would work like a SQL UPDATE: Trying to overwrite a field with the same value is just fine.

I'm submitting this as a ticket as I don't understand why it would be bad that an update didn't affect any rows. I don't care if there is any difference between the stored data and the model when I call .save() on a model. That would be application logic, I think.

And as an aside: The MySQL database I'm using reports a "0 rows affected" on a SQL UPDATE statement with identical values. It doesn't return a warning or anything.

Attachments (0)

Change History (1)

comment:1 Changed 3 months ago by shai

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

I'd expect this to happen when the object you are trying to update is not found in the database; the most likely scenario is calling save(force_update=True) with an object you've just created in memory, and have never saved; other scenarios are possible. When this is the case, not affecting any rows is indeed a bug in your code.

In the future, please ask such questions on the django-users list; you would have probably gotten an answer much faster there.


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.