Skip Menu |
 

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

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

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

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

Attachments
0002-add-debug-tracing-for-array-types-RT-129978.patch



Subject: patch: format Pg arrays
Download (untitled) / with headers
text/plain 1.6k
14:12 < ether> at what point are arrays serialized to their '{1,2,3}' form? is that way down in DBD::Pg? 14:12 < ether> I wish there was a way of making this trace output more readable: 14:12 < ether> UPDATE device SET links = array_cat_distinct(links,?), updated = now() WHERE ( ( not(links @> ?) AND id = ? ) ): 'ARRAY(0x7f940c5043f8)', 'ARRAY(0x7f940c5043f8)', 'c818345c-9e5f-41b4-a57f-f4758c72f5dd' 14:12 < ether> seeing a serialized reference is not great for debugging what I actually passed in my binds :) 14:16 < mst> ether: oh that's interesting 14:16 < mst> I bet that'll be your debug logger serialising it because it's derived from code I wrote long before I even knew pg arrays existed 14:17 < mst> gimme a minute 14:19 < mst> see if query_start in Storage::Statistics gets the un-stringified version 14:19 < mst> or check what your trace profile is 14:22 < mst> ref($schema->storage->debugobj) or something might tell you too 14:23 < ether> checking... 14:25 < ether> no, query_start gets [ '\'ARRAY(0x7faf9bf0c458)\'', ... ] in @binds 14:25 < ether> so it's ::Storage::DBI doing it, so it's fixable 14:26 < ether> yeah, _format_for_trace 14:26 < ether> ..just needs tweaking Here is a patch that DTRT, prepared against 0.082841. diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 9600389b..6f69314b 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1757,7 +1757,7 @@ sub _format_for_trace { map { defined( $_ && $_->[1] ) - ? qq{'$_->[1]'} + ? (ref($_->[1]) eq 'ARRAY' ? qq('{).join(',',map qq{"$_"},@{$_->[1]}).qq(}') : qq{'$_->[1]'}) : q{NULL} } @{$_[1] || []}; }
Download (untitled) / with headers
text/plain 807b
On Wed Jul 03 23:47:05 2019, ETHER wrote: Show quoted text
> Here is a patch that DTRT, prepared against 0.082841. > > diff --git a/lib/DBIx/Class/Storage/DBI.pm > b/lib/DBIx/Class/Storage/DBI.pm > index 9600389b..6f69314b 100644 > --- a/lib/DBIx/Class/Storage/DBI.pm > +++ b/lib/DBIx/Class/Storage/DBI.pm > @@ -1757,7 +1757,7 @@ sub _format_for_trace { > > map { > defined( $_ && $_->[1] ) > - ? qq{'$_->[1]'} > + ? (ref($_->[1]) eq 'ARRAY' ? qq('{).join(',',map qq{"$_"},@{$_-
> >[1]}).qq(}') : qq{'$_->[1]'})
> : q{NULL} > } @{$_[1] || []}; > }
Patch is insufficient, needs tests working against something like https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082841/t/72pg.t#L215-309 utilizing log-capture as in https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082841/t/storage/debug.t#L103-142
Download (untitled) / with headers
text/plain 202b
Patch attached. It will need modification to turn off the trace capture after the tests are complete (or DBIC_TRACE is neutered for the duration of the file), as I wasn't able to find how to do that.
Subject: 0002-add-debug-tracing-for-array-types-RT-129978.patch
From 19ac4f9f880351c948e85f43b32a6618ddc584e0 Mon Sep 17 00:00:00 2001 From: Karen Etheridge <ether@cpan.org> Date: Tue, 23 Jul 2019 15:19:39 -0700 Subject: [PATCH] add debug tracing for array types (RT#129978) --- lib/DBIx/Class/Storage/DBI.pm | 2 +- t/72pg.t | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 9600389b..33c0db4e 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -1757,7 +1757,7 @@ sub _format_for_trace { map { defined( $_ && $_->[1] ) - ? qq{'$_->[1]'} + ? (ref($_->[1]) eq 'ARRAY' ? qq('{).join(',',map qq{$_},@{$_->[1]}).qq(}') : qq{'$_->[1]'}) : q{NULL} } @{$_[1] || []}; } diff --git a/t/72pg.t b/t/72pg.t index a1570a59..62ba4d69 100644 --- a/t/72pg.t +++ b/t/72pg.t @@ -216,18 +216,25 @@ for my $use_insert_returning ($test_server_supports_insert_returning skip "Need DBD::Pg 2.9.2 or newer for array tests", 4 if $DBD::Pg::VERSION < 2.009002; my $arr_rs = $schema->resultset('ArrayTest'); + my @args; + $schema->storage->debugcb(sub { push @args, @_ } ); lives_ok { - $arr_rs->create({ + my $val = $arr_rs->create({ arrayfield => [1, 2], }); } 'inserting arrayref as pg array data'; + my $extra = $use_insert_returning ? ' RETURNING id' : ''; + like $args[-1], qr/\Q ( ? )${extra}: '{1,2}'\E$/, 'array bind args are rendered in trace'; + + @args = (); lives_ok { $arr_rs->update({ arrayfield => [3, 4], }); } 'updating arrayref as pg array data'; + like $args[-1], qr/\Q = ?: '{3,4}'\E$/, 'array bind args are rendered in trace'; $arr_rs->create({ arrayfield => [5, 6], -- 2.22.0


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.