Skip Menu |
 

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

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

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

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



Subject: relation id is not initialized after add_to_$relname
Download (untitled) / with headers
text/plain 1.8k
I have next relations: __PACKAGE__->table('customers'); __PACKAGE__->has_many('packages', 'SafeVPN::DB::Result::Package', 'customer_id', {cascade_delete => 0}); __PACKAGE__->table('packages'); __PACKAGE__->belongs_to('customer' => 'SafeVPN::DB::Result::Customer', 'customer_id'); __PACKAGE__->has_many('destinations', 'SafeVPN::DB::Result::Destination', 'package_id', {cascade_delete => 0}); __PACKAGE__->table('destinations'); __PACKAGE__->belongs_to('package' => 'SafeVPN::DB::Result::Package', 'package_id'); my %package = ( customer_id => $customer->id, ... destinations => [ { address_id => 33717 } ] ); Running: $DBIC->resultset('Package')->create( \%package ); OR my $package = $customer->add_to_packages(\%package); result: Can't call method "tarif" on an undefined value at /home/feelsafe/public_html/lib/SafeVPN/DB/Result/Destination.pm *line 73* at this file line 73 I have: sub new { my ( $class, $attrs ) = @_; my $self = $class->next::method($attrs); if( <some cond> ) { $val = $self->package->tarif->type; #<<<< line 73 <do calculation here, based on type, for init some null columns> } return $self; } As this is destination code, so package at this point is MUST BE created already. so in your code maybe happen next First suggestion: package is created in other transaction and destination doest not see it This is wrong suggestion, because of I must get DB FK violation Second suggestoin: after creating package row, you do not update internal structures or you do not fill package_id This is wrong sugggestion, because of this work fine: http://cpansearch.perl.org/src/FREW/DBIx-Class-0.08115/t/multi_create/torture.t Third suggestion: When I do read in mine Destination.pm@new. The read transaction does not see underlying changed, that were done in write transaction.
Download (untitled) / with headers
text/plain 1.5k
On Tue May 12 15:44:31 2015, kes-kes@yandex.ru wrote: Show quoted text
> I have next relations: > > __PACKAGE__->table('customers'); > __PACKAGE__->has_many('packages', 'SafeVPN::DB::Result::Package', > 'customer_id', {cascade_delete => 0}); > > __PACKAGE__->table('packages'); > __PACKAGE__->belongs_to('customer' => 'SafeVPN::DB::Result::Customer', > 'customer_id'); > __PACKAGE__->has_many('destinations', > 'SafeVPN::DB::Result::Destination', 'package_id', {cascade_delete => > 0}); > > > __PACKAGE__->table('destinations'); > __PACKAGE__->belongs_to('package' => 'SafeVPN::DB::Result::Package', > 'package_id'); > > > my %package = ( > customer_id => $customer->id, > ... > destinations => [ { address_id => 33717 } ] > ); > > Running: > $DBIC->resultset('Package')->create( \%package ); > OR > my $package = $customer->add_to_packages(\%package); > > result: > Can't call method "tarif" on an undefined value at > /home/feelsafe/public_html/lib/SafeVPN/DB/Result/Destination.pm *line > 73* > > at this file line 73 I have: > > sub new { > my ( $class, $attrs ) = @_; > > my $self = $class->next::method($attrs); > > if( <some cond> ) { > $val = $self->package->tarif->type; #<<<< line 73 > <do calculation here, based on type, for init some null columns> > } > > return $self; > } >
Please package the entire thing into an executable test with the extra files necessary (pushing it to github would be easiest). It is very hard to diagnose your problem with only pieces of the entire picture available.
From: kes-kes [...] yandex.ru
Download (untitled) / with headers
text/plain 2.3k
stacktrace here: [/home/feelsafe/public_html/lib/SafeVPN/DB/Result/Destination.pm:73] [/usr/share/perl5/DBIx/Class/ResultSet.pm:2593] [/usr/share/perl5/DBIx/Class/Row.pm:135] [/usr/share/perl5/DBIx/Class/Row.pm:231] [/usr/share/perl5/DBIx/Class/ResultSet.pm:2593] [/usr/share/perl5/DBIx/Class/ResultSet.pm:2260] [/home/feelsafe/public_html/lib/SafeVPN/DB/Result/Order.pm:78] [/home/feelsafe/public_html/www/orders/approve/dhandler:10] [/usr/share/perl5/Try/Tiny.pm:76] [/usr/share/perl5/DBIx/Class/Storage/BlockRunner.pm:154] [/usr/share/perl5/Context/Preserve.pm:22] [/usr/share/perl5/DBIx/Class/Storage/BlockRunner.pm:233] [/usr/share/perl5/DBIx/Class/Storage/BlockRunner.pm:125] [/usr/share/perl5/DBIx/Class/Storage.pm:187] [/usr/share/perl5/DBIx/Class/Storage/DBI.pm:860] [/usr/share/perl5/DBIx/Class/Schema.pm:654] [/home/feelsafe/public_html/www/orders/approve/dhandler:26] [/home/feelsafe/public_html/www/orders/autohandler:2] [/home/feelsafe/public_html/www/autohandler:39] [/home/feelsafe/public_html/www/layouts/v3/layout.mc:104] [/home/feelsafe/public_html/www/autohandler:41] [/usr/share/perl5/HTML/Mason/Request.pm:951] [/var/cache/mason/obj/2435440036/autohandler.obj:24] Now step by step: [/usr/share/perl5/DBIx/Class/ResultSet.pm:2260] sub populate{ ... @results = map { $self->new_result($_)->insert } @$data; Here you create rows first in memory (new_result) and then post them to DB (insert) [/usr/share/perl5/DBIx/Class/ResultSet.pm:2593] sub new { .... $rel_obj = $new->__new_related_find_or_new_helper($key, $rel_obj); Here you are trying to create children rows before parent row exists This patch fix that: https://github.com/dbsrgits/dbix-class/pull/78 But problem still exists. I think, may be, DBIx::Class::Relationship::Accessor; at line 57: my $val = $self->search_related( %1$s )->single; this relation_ship_accessor do not find rows in memory. because of this package DBIx::Class::Relationship::Base; line 531 $rsrc->_resolve_condition( $rel_info->{cond}, $rel, $self, $rel ) return UNRESOLVABLE_CONDITION \"1 = 0" maybe because row not in database yet. It just sit in memory now. and here package DBIx::Class::ResultSource; I loose clue I have only one note sub _resolve_condition { .... line 1819: my $args = { does not have data about package relationship the "self_result_object->_relationship_data" has info about address only Any suggestions?
From: kes-kes [...] yandex.ru
attached project files.
Subject: savevpn.tar
Download savevpn.tar
application/x-tar 20k

Message body not shown because it is not plain text.

From: kes-kes [...] yandex.ru
Download (untitled) / with headers
text/plain 799b
Is anywhere DOC about table structure for tests? Or you can add next code himself. I think it will be better to have testcase for my case. This reproduce my FAIL case: package SafeVPN::DB::Result::Parent; __PACKAGE__->table('parent'); __PACKAGE__->add_columns( id => { sequence => 'uid_seq' }, 'info' ); __PACKAGE__->has_many('children', 'SafeVPN::DB::Result::Children', 'parent_id', {cascade_delete => 0}); package SafeVPN::DB::Result::Children; __PACKAGE__->table('child'); __PACKAGE__->add_columns( id => { sequence => 'uid_seq' }, qw( parent_id info ) ); __PACKAGE__->belongs_to('parent' => 'SafeVPN::DB::Result::Parent', 'parent_id'); sub new { my ( $class, $attrs ) = @_; my $self = $class->next::method($attrs); $self->info( $self->parent->info ); return $self; }
From: kes-kes [...] yandex.ru
Download (untitled) / with headers
text/plain 268b
$schema->resultset('Parent')->create({ info => 'test', children => [ [], [] ] #children 'info' field are autofilled at Parent::new }); After this you must have one row at parent: id | info 1|test And two rows at children: id|parent_id|info 1|1|test 2|1|test


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.