Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | drupal_write_record-multi-key-plus-tests.patch | 3.35 KB | nedjo |
#4 | drupal_write_record-tests.patch | 2.78 KB | nedjo |
drupal_write_record-multi-key.patch | 595 bytes | nedjo | |
Comments
Comment #1
nedjoI'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.
Comment #2
Dries CreditAttribution: Dries commentedLooks good -- would be better if it came with some tests. :)
Comment #3
nedjoHere 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.
Comment #4
nedjoWith attachment.
Comment #6
nedjoThe previous patch's 2 failures confirmed the current bug. Here's a patch with the fix and tests.
Comment #8
nedjoReally testbot? Can you try again?
Comment #9
catchAll looks great to me, tests make it very clear what the desired behaviour is. RTBC.
Comment #10
webchickLooks good. Thanks, Nedjo!
Committed to HEAD.