Skip Menu |
 

This queue is for tickets about the DBIx-Class CPAN distribution.

Report information
The Basics
Id: 57379
Status: rejected
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: christian.koetschan [...] googlemail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: DBIx-Class-0.08121 - update_all uses wrong value for primary key in WHERE clause
Date: Tue, 11 May 2010 18:17:12 +0200
To: bug-DBIx-Class [...] rt.cpan.org
From: Christian Koetschan <christian.koetschan [...] googlemail.com>
Download (untitled) / with headers
text/plain 1021b
Hi, I'm using update_all in a Catalyst/Postgres environment from DBIx-Class-0.08121.tar.gz on a x86_64 GNU/Linux. The following hashreference is passed to update_all(): [debug] $VAR1 = { 'magazine' => 'Magazine TEST', 'pubdate' => '2010-04-21T00:00:00', 'id' => 18 }; The resulting error: ( I executed "my $success = $c->model('DBModel::Pressrelease')->update_all($c->request->data->{jsonresponse});") [error] DBIx::Class::ResultSet::update_all(): DBI Exception: DBD::Pg::st execute failed: ERROR: duplicate key violates unique constraint "pressreleases_pkey" [for Statement "UPDATE pressreleases SET id =?, magazine = ?, pubdate = ? WHERE ( id = ? )" with ParamValues: 1='18', 2='Magazine TEST', 3='2010-04-21T00:00:00', 4='10'] The Problem in the generated SQL statement is that ParamValue 4 (the one in the WHERE clause) is 10 and not 18. I have no clue where this 10 is coming from. My primary key is set to "id", and the structure of the statement looks correct to me.
Download (untitled) / with headers
text/plain 1.8k
On Tue May 11 12:17:27 2010, christian.koetschan@googlemail.com wrote: Show quoted text
> Hi, > > I'm using update_all in a Catalyst/Postgres environment from > DBIx-Class-0.08121.tar.gz on a x86_64 GNU/Linux. > > The following hashreference is passed to update_all(): > > [debug] $VAR1 = { > 'magazine' => 'Magazine TEST', > 'pubdate' => '2010-04-21T00:00:00', > 'id' => 18 > }; > > > The resulting error: > ( I executed "my $success = > $c->model('DBModel::Pressrelease')->update_all($c->request->data-
> >{jsonresponse});")
> > [error] DBIx::Class::ResultSet::update_all(): DBI Exception: > DBD::Pg::st > execute failed: ERROR: duplicate key violates unique constraint > "pressreleases_pkey" [for Statement "UPDATE pressreleases SET id =?, > magazine = ?, pubdate = ? WHERE ( id = ? )" with ParamValues: 1='18', > 2='Magazine TEST', 3='2010-04-21T00:00:00', 4='10'] > > > The Problem in the generated SQL statement is that ParamValue 4 (the > one in > the WHERE clause) is 10 and not 18. I have no clue where this 10 is > coming > from. My primary key is set to "id", and the structure of the > statement > looks correct to me.
From the docs: 'Fetches all objects and updates them one at a time.' So your snippet is equivalent to: my $rs = $c->model('DBModel::Pressrelease'); while (my $x = $rs->next) { $x->update($c->request->data->{jsonresponse}) } Therefore I'm guessing that the id = 10 is coming from the existing values of the primary key column from an existing row. In other words, using update_all and passing in a primary key to update doesn't make a huge amount of sense as it will try to set all rows to the same primary key. I think this is a case of using the wrong method - you probably want search + update instead. I'm closing this ticket, feel free to reopen it with more details if there is still a problem


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.