Skip Menu |
 

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

Report information
The Basics
Id: 114440
Status: new
Priority: 0/
Queue: DBIx-Class-Tree-NestedSet

People
Owner: Nobody in particular
Requestors: ribasushi [...] leporine.io
Cc:
AdminCc:

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

Attachments
0001-Fix-for-upcoming-DBIx-Class-0.082900-release.patch



Subject: Upcoming DBIC change will break this module entirely (PATCH attached)
Download (untitled) / with headers
text/plain 535b
The culprit is this DBIC-side change: https://github.com/dbsrgits/dbix-class/commit/e5053694 It was already unsafe to only override search_related, as someone could trivially do related_resultset("foo")->search, but now DBIC itself is using this direct call internally. Attached is a patch with the necessary fix. P.S. Yes, this is a disruptive change. An almost finished-but-not-yet-landed commit properly detects and warns in such cases of overriding the "wrong" method. The upcoming release will *NOT* break your code silently.
Subject: 0001-Fix-for-upcoming-DBIx-Class-0.082900-release.patch
From c86daa2619e8f12dd39a2dc17133833bc77a4476 Mon Sep 17 00:00:00 2001 From: Peter Rabbitson <ribasushi@cpan.org> Date: Tue, 17 May 2016 16:54:16 +0200 Subject: [PATCH] Fix for upcoming DBIx::Class 0.082900 release As part of a 'callpath normalization' effort overriding search_related now almost never works (as opposed to the previous case of sometimes not working) As there is no way to correct this transparrently, changes to your module are necessary in order for things to keep working properly. Sorry for the trouble --- lib/DBIx/Class/Tree/NestedSet.pm | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/lib/DBIx/Class/Tree/NestedSet.pm b/lib/DBIx/Class/Tree/NestedSet.pm index 6ef627b..e885d1e 100755 --- a/lib/DBIx/Class/Tree/NestedSet.pm +++ b/lib/DBIx/Class/Tree/NestedSet.pm @@ -221,23 +221,36 @@ sub create_related { return $row; } -# search_related with special handling for relationships +# related_resultset with special handling for ancestry relationships # -sub search_related { - my ($self, $rel, $cond, @rest) = @_; - my $pk = ($self->result_source->primary_columns)[0]; - - $cond ||= {}; - if ($rel eq 'descendants' || $rel eq 'children') { - $cond->{"parent.$pk"} = $self->$pk, - } - elsif ($rel eq 'ancestors' || $rel eq 'parent') { - $cond->{"child.$pk"} = $self->$pk, +sub related_resultset { + my ($self, $rel) = @_; + + my $rs = $self->next::method($rel); + + my $type; + if ( + ( + ( $rel eq 'descendants' or $rel eq 'children' ) + and + $type = 'parent' + ) + or + ( + ( $rel eq 'ancestors' or $rel eq 'parent' ) + and + $type = 'child' + ) + ) { + my ($pk_col) = $self->result_source->primary_columns; + + $rs = $rs->search_rs({ + "$type.$pk_col" => $self->$pk_col + }); } - return $self->next::method($rel, $cond, @rest); + $rs; } -*search_related_rs = \&search_related; # Insert a node anywhere in the tree # left -- 2.1.4


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.