datetime default value error

55 views
Skip to first unread message

Uriel

unread,
Jul 13, 2012, 3:59:16 PM7/13/12
to rose-db...@googlegroups.com
Hello,

I have the following object:

__PACKAGE__->meta->setup
(
    table => 'coupon',

    columns =>
    [
        id                            => { type => 'bigint', primary_key => 1 },
        store                         => { type => 'bigint' },
        name                          => { type => 'varchar', length => 45 },
        excerpt                       => { type => 'varchar', length => 150 },
        description                   => { type => 'text' },
        quantity                      => { type => 'int', default => 1 },
        quantity_available            => { type => 'int', default => 0 },
        quantity_claimed_subscriber   => { type => 'int', default => 0 },
        quantity_claimed_free         => { type => 'int', default => 0 },
        limitation                    => { type => 'int', default => 0 },
        limitation_int                => { type => 'int' },
        offer_creation                => { type => 'datetime', default => 'now', time_zone => 'UTC' },
        offer_start                   => { type => 'datetime', time_zone => 'UTC' },
        offer_end                     => { type => 'datetime', time_zone => 'UTC' },
        expiration_int                => { type => 'int', default => 0 },
        expiration_mult               => { type => 'char', length => 1, default => 'D' },
        delivery_type                 => { type => 'char', length => 1, default => 1 },
        random_codes                  => { type => 'boolean', default => 1 },
        status                        => { type => 'tinyint', default => 0 },
        purchase_price                => { type => 'decimal' },
    ],

);

Whenever I create a new object and save it, it saves the object correctly on the database but then it dies with the following error:

"Could not parse datetime 'now' - Invalid date format: now"

This is really strange, since it does save the object with the correct date on the database.

Any pointers on what might be the problem?

John Siracusa

unread,
Jul 13, 2012, 6:34:19 PM7/13/12
to rose-db...@googlegroups.com
On Fri, Jul 13, 2012 at 3:59 PM, Uriel <uriel....@gmail.com> wrote:
> Whenever I create a new object and save it, it saves the object correctly on
> the database but then it dies with the following error:
>
> "Could not parse datetime 'now' - Invalid date format: now"
>
> This is really strange, since it does save the object with the correct date
> on the database.
>
> Any pointers on what might be the problem?

Nothing comes to mind. It looks like "now" is making it past the
first level of parsing by Rose::DateTime::Util's parse_date() method
(which does understand "now") and to the per-database date parsing
code, which probably doesn't. But I don't see why that would happen.
I suggest stepping through the problematic code in the debugger to see
what's going on. Failing that, make a self-contained test case that
anyone can run and post it to the list.

-John

Richard Jones

unread,
Jul 14, 2012, 4:28:00 AM7/14/12
to rose-db...@googlegroups.com
On 13/07/2012 20:59, Uriel wrote:
[..]
> Whenever I create a new object and save it, it saves the object
> correctly on the database but then it dies with the following error:
>
> "Could not parse datetime 'now' - Invalid date format: now"
>
> This is really strange, since it does save the object with the correct
> date on the database.
>
> Any pointers on what might be the problem?

You're not being bitten by a misuse of the $db->error 'feature'?

$db->do_transaction( sub { ... } );
return $db->error if $db->error; # THIS IS WRONG

That bites in a persistent environment. I'm sure John will fill in the
details, but it's returning a silent warning stored during an earlier
date-handling instance.

<https://groups.google.com/forum/#!search/rdbo$20jones/rose-db-object/SpFwgo2gBW4/-8mpMTeu88wJ>

In my case the error msg was exactly as yours, and the transaction
worked fine, and I should have (and now do):

my $ok = $db->do_transaction( sub { ... } );
return $ok ? 0 : 'my_method() error - ' . $db->error;

Just a thought.
--
Richard Jones


John Siracusa

unread,
Jul 14, 2012, 10:13:45 AM7/14/12
to rose-db...@googlegroups.com
On Sat, Jul 14, 2012 at 4:28 AM, Richard Jones <ra.j...@dpw.clara.co.uk> wrote:
> You're not being bitten by a misuse of the $db->error 'feature'?
>
> $db->do_transaction( sub { ... } );
> return $db->error if $db->error; # THIS IS WRONG
>
> That bites in a persistent environment. I'm sure John will fill in the
> details, but it's returning a silent warning stored during an earlier
> date-handling instance.
>
> <https://groups.google.com/forum/#!search/rdbo$20jones/rose-db-object/SpFwgo2gBW4/-8mpMTeu88wJ>
>
> In my case the error msg was exactly as yours, and the transaction worked
> fine, and I should have (and now do):
>
> my $ok = $db->do_transaction( sub { ... } );
> return $ok ? 0 : 'my_method() error - ' . $db->error;

Ah, yes, this sounds like it could very well be what's happening. Good catch.

-John

Uriel

unread,
Jul 18, 2012, 11:14:28 AM7/18/12
to rose-db...@googlegroups.com
Thanks for your comments, I don't think this is the problem in particular since the error comes when I do:

$coupon->save

And what is strange, is that it does the save in the database with the correct date and then after that it throws the error.
Reply all
Reply to author
Forward
0 new messages