While going through some existing Customer Profile code, I noticed that all code unsets both the $profile->profile_id and $profile->revision before saving a profile 'as a copy'.

Messing with profiles (copying to a new object) is a common-ish operation and will be done by more contrib people; maybe someone will want to mass-create similar entities using some script. So what happens when they only unset the ID and not the revision ID?

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 
Duplicate entry '2958' for key 'revision_id': INSERT INTO ...

Ah. Well, it doesn't cause data corruption if a developer is being sloppy. Good news. But still, maybe the following patch is a good idea?

(Entity API does basically the same thing - that is, it always clears out the revision ID. Not the log.)

--

PS: the deleted 2 comment lines don't have anything to do with this patch but they were confusing / didn't contain useful info for that point in the code.
"create the row in the base table, then save the revision" is always done.

CommentFileSizeAuthor
commerce_entity-revision-unset.patch1.55 KBroderik
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Status: Needs review » Needs work

The last submitted patch, commerce_entity-revision-unset.patch, failed testing.