Skip Menu |
 

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

Report information
The Basics
Id: 73876
Status: open
Priority: 0/
Queue: DBIx-Class-Schema-Loader

People
Owner: Nobody in particular
Requestors: TIMB [...] cpan.org
Cc:
AdminCc:

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

Attachments


Subject: Optionally warn when a relationship is redefined [PATCH]
Download (untitled) / with headers
text/plain 966b
We've been using Schema::Loader for years on a large postgresql database. Over the years we've had to add manual relationships to the generated schema files because S:L was missing them for various reasons (often because they weren't declared in the database itself yet). Now our schema is more complete and S:L is better at finding relationships and is adding them to the generated schema files. However, they're being silently overridden by the manual relationships we added previously. The old manually added relationships are usually incomplete and sometimes plain wrong. The attached patch makes it easy to identify redefined relationships. It carps is a relationship is redefined while DBIC_TRACE is set. Some other env var or control mechanism could be used, I just picked DBIC_TRACE as an easy option. (I'd be happy if warnings were the default and were silenced by adding an attribute like is_redefintion=>1 to the new relationship definition.)
Subject: dbix-class-rel-redef-warn.patch
diff --git a/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm b/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm index 075c331..4d6f199 100644 --- a/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm +++ b/cpan-5.008/lib/perl5/DBIx/Class/ResultSource.pm @@ -1085,6 +1085,12 @@ sub add_relationship { } my %rels = %{ $self->_relationships }; + if ($rels{$rel} && $ENV{DBIC_TRACE}) { + # warning is useful e.g. for large Schema::Loader generated schemas where + # relationships have been added manually and then later generated by + # Schema::Loader. + carp "$rel relationship redefined"; + } $rels{$rel} = { class => $f_source_name, source => $f_source_name, cond => $cond,
Committed to topic/rel_redef_warn
Subject: Re: [rt.cpan.org #73876] Optionally warn when a relationship is redefined [PATCH]
Date: Wed, 11 Jan 2012 03:41:27 -0500
To: Tim_Bunce via RT <bug-DBIx-Class [...] rt.cpan.org>
From: Peter Rabbitson <ribasushi [...] cpan.org>
Download (untitled) / with headers
text/plain 1.6k
On Tue, Jan 10, 2012 at 07:46:36AM -0500, Tim_Bunce via RT wrote: Show quoted text
> Tue Jan 10 07:46:34 2012: Request 73876 was acted upon. > Transaction: Ticket created by TIMB > Queue: DBIx-Class > Subject: Optionally warn when a relationship is redefined [PATCH] > Broken in: (no value) > Severity: Unimportant > Owner: Nobody > Requestors: TIMB@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=73876 > > > > We've been using Schema::Loader for years on a large postgresql database. Over the years > we've had to add manual relationships to the generated schema files because S:L was missing > them for various reasons (often because they weren't declared in the database itself yet). > > Now our schema is more complete and S:L is better at finding relationships and is adding > them to the generated schema files. However, they're being silently overridden by the manual > relationships we added previously. The old manually added relationships are usually > incomplete and sometimes plain wrong. >
Newer versions of S::L are detecting such cases and issue the corresponding warnings. If your S::L is upgraded, and you are not seeing those - this is a bug in S::L itself. The other consideration to take is that silent overrides can happen on column accessors, in adition to relationship accessors. S::L is supposed to detect this as well (also it should detect static compile-time sub{}s). As far as the patch is concerned - I am really wary of tying warn-toggle semantics into DBIC_TRACE itself. I will be back on IRC next Monday, we can discuss options then. Cheers


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.