drupal_write_record() tests for a last insert ID and returns FALSE if none is found. However, it appears that this ID is returned only for single-field primary key tables. If there is a multi-field primary key, no insert ID is returned and drupal_write_record() returns FALSE instead of the correct value of SAVED_NEW or SAVED_UPDATED.

Patch ensures FALSE is returned only if there is a single-field primary key.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nedjo’s picture

Status: Active » Needs review

I'm going to include this patch also in #361597: CRUD API for locale source and locale target strings because without it a test there fails.

Dries’s picture

Looks good -- would be better if it came with some tests. :)

nedjo’s picture

Here is a basic set of tests on drupal_write_record(). They could be extended but I'd rather do that as part of #365899: API methods for schema-based load and delete operations.

With this test patch, two tests should fail, for the return values from drupal_write_record() on insert and update for tables with multi-field primary keys. With drupal_write_record-multi-key.patch these tests will pass.

nedjo’s picture

With attachment.

Status: Needs review » Needs work

The last submitted patch failed testing.

nedjo’s picture

Status: Needs work » Needs review
FileSize
3.35 KB

The previous patch's 2 failures confirmed the current bug. Here's a patch with the fix and tests.

Status: Needs review » Needs work

The last submitted patch failed testing.

nedjo’s picture

Status: Needs work » Needs review

Really testbot? Can you try again?

catch’s picture

Status: Needs review » Reviewed & tested by the community

All looks great to me, tests make it very clear what the desired behaviour is. RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Looks good. Thanks, Nedjo!

Committed to HEAD.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.