Skip Menu |

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

Report information
The Basics
Id: 104839
Status: open
Priority: 0/
Queue: DBIx-Class

People
Owner: Nobody in particular
Requestors: kes-kes [...] yandex.ru
Cc:
AdminCc:

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



Subject: Can not update_or_create
line: 370 $DBIC->resultset( $table )->update_or_create( $row, { key => 'primary' } ); Cause next error: bless({ msg => "DBIx::Class::ResultSource::_minimal_valueset_satisfying_constraint(): Unable to satisfy requested constraint 'primary', missing values for column(s): 'id' at /home/feelsafe/public_html/www/autohandler line 370\n", }, "DBIx::Class::Exception") This behaviour is unexpected Because of when I do not supply 'id' (values for primary key fields) I expect find will FAIL and new row is created EXPECTED: new row is created when no value for primary key field
On Mon Jun 01 15:57:23 2015, kes-kes@yandex.ru wrote: Show quoted text
> line: 370 > $DBIC->resultset( $table )->update_or_create( $row, { key => > 'primary' } ); > > Cause next error: > bless({ > msg => > "DBIx::Class::ResultSource::_minimal_valueset_satisfying_constraint(): > Unable to satisfy requested constraint 'primary', missing values for > column(s): 'id' at /home/feelsafe/public_html/www/autohandler line > 370\n", > }, "DBIx::Class::Exception") > > > This behaviour is unexpected >
This is correct. Introduced in b7743dabe, and also never reported as problematic since... Bizarre. This will be fixed in one manner or another before 0.082829
From: kes-kes [...] yandex.ru
diff --git a/lib/DBIx/Class/ResultSet.pm b/lib/DBIx/Class/ResultSet.pm index a44a9eb..300ebdb 100644 --- a/lib/DBIx/Class/ResultSet.pm +++ b/lib/DBIx/Class/ResultSet.pm @@ -3031,7 +3031,9 @@ sub update_or_create { my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {}); my $cond = ref $_[0] eq 'HASH' ? shift : {@_}; - my $row = $self->find($cond, $attrs); + # It is OK, if find row fail. We will then 'create' instead of 'update' + my $row = eval { $self->find($cond, $attrs) }; + # warn $@; if (defined $row) { $row->update($cond); return $row;
From: kes-kes [...] yandex.ru
does this patch looks ok?
On Wed Jul 08 20:53:31 2015, kes-kes@yandex.ru wrote: Show quoted text
> does this patch looks ok?
No, an eval frame is rather expensive in this case. Also it does not address any of the other X_or_Y methos. I am currently working on a refactor of find, which among other things addresses this. Sorry it's been a while - all of the recent work got prompted by your original reports, it's just... trickier than anticipated.