[Dbix-class] Re: DateTime objects passed to search() are not
supported properly
Peter Rabbitson
rabbit+dbic at rabbit.us
Thu Sep 20 20:02:47 GMT 2012
On Thu, Sep 20, 2012 at 12:44:31PM -0700, Bill Moseley wrote:
> On Thu, Sep 20, 2012 at 3:22 AM, Peter Rabbitson <rabbit+dbic at rabbit.us>wrote:
>
> >
> > Precisely. The problem is that we can not invoke the correct IC::DT
> > deflation routine to respect possible time_zone settings. The formatter is
> > fine for use only as that - a formatter. There is no practical way to tie
> > the IC::DT metadata to your search criteria. There is no change in behavior
> > - DBIC has always done the wrong thing (simply stringifying the DT object).
> > What changed is that now you are getting a warning about it.
>
>
> Sorry, I'm being a bit slow here.
>
> Quoting the Cookbook again:
>
>
> my $dtf = $schema->storage->datetime_parser;
> my $rs = $schema->resultset('users')->search(
> {
> signup_date => {
> -between => [
> $dtf->format_datetime($dt_start),
> $dtf->format_datetime($dt_end),
> ],
> }
> },
> );
>
>
> So, if $dt_start is not floating (has a timezone) then
> $dtf->format_datetime( $dt_start ) would be a sting that included the
> timezone which is needed to specify a point in time to the database.
>
> Is the problem that the above query is passed directly to SQL::Abstract
> which doesn't have access to the storage object, and thus cannot get at the
> formatter?
No. Look at [1], search for 'If you want to set a specific timezone'.
>
> Couldn't something like Data::Visitor be used to find all the DateTIme
> objects in the criteria and then run them through the formater? search()
> can get at the storage object, right?
And you do not see a problem with such a selective and error-prone approach?
Again - the problem is not that we can not apply the cookbook example
automatically. The problem is that search({t => $dt}) and find({t => $dt})
can not be made equivalent for all cases. Because whoever designed IC::DT
(and IC in general) at the time didn't think through much of anything. There
are years and years of code working around this deficiency. The best one can
do is issue an informative warning (and I will be happy to see a patch
clarifying the warning text). "Fixing" this in an 80/20 fashion is not
something I am looking forward to do.
[1] https://metacpan.org/module/DBIx::Class::InflateColumn::DateTime
More information about the DBIx-Class
mailing list