How to debug?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to debug?

Paul Mooney
Hello,

I have a bug that happens /sometimes/. Replicating it is a pain.
I would like advice on how to debug it...
Because I'm scratching my head.

If I run our full test suite (takes about 20 minutes) I sometimes get
JOINs where there should not be JOINs. It's like something has been
cached somewhere and it's remembering a previous query... but I can't
see how they is possible...

My code is inside a Result class. It looks like this:

   my @some_items =
$self->result_source->schema->resultset("FulfilmentItem")->search({fulfilment_item_status_id
=> { -in => [5,9,69696969] } })->all;

But sometimes I get SQL generated *with JOINs*... WTF?:

SELECT me.id, <more_fields>
FROM fulfilment_item me
JOIN fulfilment fulfilment ON fulfilment.id = me.fulfilment_id
LEFT JOIN mts_hook mts_hook ON mts_hook.fulfilment_item_id = me.id
WHERE ( ( ( fulfilment.allocation_id = ? OR fulfilment.allocation_id = ?
OR fulfilment.allocation_id = ? OR fulfilment.allocation_id = ? ) AND
fulfilment_item_status_id IN ( ?, ?, ? ) ) )
: 'taBE4E1BE6-07D9-11E6-9001-984A2B909FEA',
'taBF55B3A0-07D9-11E6-9001-984A2B909FEA',
'taC09556B2-07D9-11E6-9001-984A2B909FEA',
'taC1DCBE98-07D9-11E6-9001-984A2B909FEA', '5', '9', '69696969'

If I run the test on its own there are no JOINs.

perl v5.20.3
DBIx::Class::VERSION = 0.082820

Any ideas?
All advice welcome.


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: How to debug?

Marco
Excerpts from Paul Mooney's message of 2016-04-22 12:09:04 +0100:

> Hello,
>
> I have a bug that happens /sometimes/. Replicating it is a pain.
> I would like advice on how to debug it...
> Because I'm scratching my head.
>
> If I run our full test suite (takes about 20 minutes) I sometimes get
> JOINs where there should not be JOINs. It's like something has been
> cached somewhere and it's remembering a previous query... but I can't
> see how they is possible...
>
> My code is inside a Result class. It looks like this:
>
>    my @some_items =
> $self->result_source->schema->resultset("FulfilmentItem")->search({fulfilment_item_status_id
> => { -in => [5,9,69696969] } })->all;
>
> But sometimes I get SQL generated *with JOINs*... WTF?:

If any previous search is getting in the way (since chaining search is
possible, btw one of the greatest features of DBIx). You can 'flush'
any previous 'search call' by just hitting the database, so you can:

# hit the db, to flush any previous search.
$self->result_source->schema->resultset("FulfilmentItem")->search({})->first;

# continue testing...

But, this is just a workaround, the problem should be verified to
confirm what previous search is getting in the way, if any.

>
> SELECT me.id, <more_fields>
> FROM fulfilment_item me
> JOIN fulfilment fulfilment ON fulfilment.id = me.fulfilment_id
> LEFT JOIN mts_hook mts_hook ON mts_hook.fulfilment_item_id = me.id
> WHERE ( ( ( fulfilment.allocation_id = ? OR fulfilment.allocation_id = ?
> OR fulfilment.allocation_id = ? OR fulfilment.allocation_id = ? ) AND
> fulfilment_item_status_id IN ( ?, ?, ? ) ) )
> : 'taBE4E1BE6-07D9-11E6-9001-984A2B909FEA',
> 'taBF55B3A0-07D9-11E6-9001-984A2B909FEA',
> 'taC09556B2-07D9-11E6-9001-984A2B909FEA',
> 'taC1DCBE98-07D9-11E6-9001-984A2B909FEA', '5', '9', '69696969'
>
> If I run the test on its own there are no JOINs.
>
> perl v5.20.3
> DBIx::Class::VERSION = 0.082820
>
> Any ideas?
> All advice welcome.
>

--
Marco Arthur @ (M)arco Creatives

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...