Skip Menu |

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

Report information
The Basics
Id: 115381
Status: resolved
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: wesdmalone [...] gmail.com
Cc:
AdminCc:

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



Subject: Column value bleeds over from previous create call (MSSQL-only?)
Date: Thu, 16 Jun 2016 18:25:55 -0500
To: bug-DBIx-Class [...] rt.cpan.org
From: Wes Malone <wesdmalone [...] gmail.com>
I found this one by accident. When creating a row for a result with a missing 'is_auto_increment' prop in it's ident column, the new row object receives the ident value from a previous row. Mildly flaky test follows: use 5.20.0; use warnings; use lib 'lib'; use Test::More; use MyApp::Schema; my $s = MyApp::Schema->connect($ENV{DBIC_TEST_CONN_STR}); $s->resultset($_)->delete for qw(Artist Cd Track); my $art = $s->resultset("Artist")->create({ name => 'ZZZ' }); diag 'Artist id: '.$art->id; my $cd = $art->create_related(cds => { title => 'YYY' }); my $cd_from_db = $s->resultset("Cd")->search({ title => 'YYY' })->next; diag 'CD id: '.$cd->id; diag 'Actual CD id: '.$cd_from_db->id; isnt $cd->id, $art->id, 'created objects id should not come from the previous object'; my $track = $cd->create_related(tracks => { title => 'XXX' }); # FK error done_testing; And the output is $ perl dbic-test.pl # Artist id: 15 # CD id: 15 # Actual CD id: 110 not ok 1 - created objects id should not come from the previous object # Failed test 'created objects id should not come from the previous object' # at dbic-test.pl line 16. # got: '15' # expected: anything else DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::ODBC::st execute failed: [Microsoft][SQL Server Native Client 11.0][SQL Server]The INSERT statement conflicted with the FOREIGN KEY constraint "track_fk_cdid". The conflict occurred in database "dbic_test", table "dbo.cd", column 'id'. (SQL-23000) [state was 23000 now 01000] [Microsoft][SQL Server Native Client 11.0][SQL Server]The statement has been terminated. (SQL-01000) [for Statement "INSERT INTO track ( cdid, title) VALUES ( ?, ? ) SELECT SCOPE_IDENTITY()" with ParamValues: 1='15', 2='XXX'] at dbic-test.pl line 18 Full repro code is here https://github.com/wesQ3/dbic-reused-ident.git I wasn't able to repro with SQLite, so this may be MSSQL specific. The provided deploy SQL has the identity seeds for each table staggered by 100, so failures are easily spotted. If you just started with blank tables at ID 1, your FK's would match :) DBIC 0.082821 DBD::ODBC 1.50 SQL Server Native Client 11.0 for Linux perl 5.20.1
On Fri Jun 17 01:26:38 2016, wesdmalone@gmail.com wrote: Show quoted text
> I found this one by accident. When creating a row for a result with a > missing 'is_auto_increment' prop in it's ident column, the new row > object receives the ident value from a previous row. >
Argh... so much grief... This is now fixed for good via https://github.com/dbsrgits/dbix-class/commit/7305f6f93, read commit msg for more details. Thanks for the report!
Subject: Re: [rt.cpan.org #115381] Column value bleeds over from previous create call (MSSQL-only?)
Date: Tue, 13 Sep 2016 13:04:46 -0500
To: bug-DBIx-Class [...] rt.cpan.org
From: Wes Malone <wesdmalone [...] gmail.com>
That's a hell of a conditional! Good error message, too. Thanks for your help. On Tue, Sep 13, 2016 at 11:06 AM, Peter Rabbitson via RT < bug-DBIx-Class@rt.cpan.org> wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=115381 > > > On Fri Jun 17 01:26:38 2016, wesdmalone@gmail.com wrote:
> > I found this one by accident. When creating a row for a result with a > > missing 'is_auto_increment' prop in it's ident column, the new row > > object receives the ident value from a previous row. > >
> > Argh... so much grief... This is now fixed for good via > https://github.com/dbsrgits/dbix-class/commit/7305f6f93, read commit msg > for more details. > > Thanks for the report! >
This is finally on CPAN as https://metacpan.org/release/RIBASUSHI/DBIx-Class-0.082842 Sorry for the long road to get there.