Here's 6003 as an example:
function password_policy_update_6003() {
$ret = array();
$ret[] = db_add_unique_key($ret, 'password_policy','name', array('name'));
return $ret;
}
The basic problem is that db_add_unique_key() doesn't have an explicit return since it is using the pass-by-reference variable $ret to add the result to. Consquently, there will be a NULL added to $ret after the result that db_add_unique_key() put in there.
Later on down the line when Drupal is continuing with the update process, update_results_page() will be called to generate the results details and you'll get something like this:
Update #6003
ALTER TABLE {password_policy} ADD UNIQUE KEY name (name)
Failed:
That NULL array entry that got tacked on results in a blank "Failed:" message, which makes it look like the update didn't work correctly (although it actually did).
All three of those update functions have the same problem. Essentially all that needs to happen is that "$ret[] =" needs to removed in that second line.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 1174748-false-failures-on-updates-9.patch | 2.31 KB | erikwebb |
| #7 | 1174748-false-failures-on-updates.patch | 2.3 KB | erikwebb |
Comments
Comment #1
earth1 commentedI tried this on: db_change_field(&$ret, 'password_policy', 'policy', 'policy', array(
$ret[] = db_change_field(&$ret, 'password_policy', 'policy', 'policy', array(
but it doesn't work. Please help!
Comment #2
bryan kennedy commentedI noticed the same issue in upgrading to 6.x-1.0 just now. Since this relates to database integrity, I increased the priority.
Comment #3
LonitaD commentedSame problem here.
Comment #4
AlexisWilke commentedFYI, I got those after upgrade from a version from last year to April's version:
* warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "," LINE 1: update password_policy_role pr, password_policy pp set pr.na... ^ in /usr/clients/www_html/new.m2osw.com/public_html/includes/database.pgsql.inc on line 188.
* user warning: query: update password_policy_role pr, password_policy pp set pr.name = pp.name where pr.pid = pp.pid in /usr/clients/www_html/new.m2osw.com/public_html/sites/all/modules/password_policy/password_policy.install on line 344.
* warning: pg_query() [function.pg-query]: Query failed: ERROR: could not create unique index "password_policy_role_name_key" DETAIL: Table contains duplicated values. in /usr/clients/www_html/new.m2osw.com/public_html/includes/database.pgsql.inc on line 188.
* user warning: query: ALTER TABLE password_policy_role ADD CONSTRAINT password_policy_role_name_key UNIQUE (rid,name) in /usr/clients/www_html/new.m2osw.com/public_html/includes/database.pgsql.inc on line 841.
I'm using PostgreSQL and apparently you have a couple problems with that db...
Comment #5
glenshewchuck commentedFYI - still got the error updating from 6.x-1.0-beta1 to 6.x-1.0 (2011-May-19). Error: "Failed" messages on updates 6003, 6004, and 6006
Comment #6
AlexisWilke commentedAs a side note, that's not going to work in PostgreSQL. You cannot have more than one table in the UPDATE. If you need more, you have to use the FROM parameter.
UPDATE password_policy_role pr, password_policy pp SET pr.name = pp.name WHERE pr.pid = pp.pid
Probably something like this:
UPDATE password_policy_role pr SET pr.name = pp.name FROM password_policy pp WHERE pr.pid = pp.pid
And I'm not so sure it would work with MySQL.
Thank you.
Alexis
Comment #7
erikwebb commentedPatch attached that should fix these issues. Please RTBC and I'll commit the changes.
@AlexisWilke - Any thoughts on a PostgreSQL-compliant patch?
(Downgrading priority as this is erroneous output, not broken code.)
Comment #8
ChrisLaFrancis commentedI posted a patch in 1129682 back in April for PostgreSQL compatibility in update 6005.
Changing
$ret[] = update_sql("update {password_policy_role} pr, {password_policy} pp set pr.name = pp.name where pr.pid = pp.pid");to
$ret[] = update_sql("update {password_policy_role} pr set name = (select name from {password_policy} pp where pr.pid = pp.pid)");works in PostgreSQL 8.4.7. Not sure about MySQL... but from reading the documentation I think it should work there, too.
Comment #9
erikwebb commentedRe-rolled patch with fivefrank's suggested PostgreSQL compatibility change. Any confirmation from the MySQL side?
Comment #10
ezra-g commentedI tested this patch on MySQL 5.5.9 and the updates run without error. This seems RTBC.
Comment #11
erikwebb commentedDone and committed! - http://drupalcode.org/project/password_policy.git/commit/7b3120a
Comment #13
erikwebb commentedTagging