[Dbix-class] Trouble updating columns (possible bug or not enough DWIM)

Christopher H. Laco claco at chrislaco.com
Thu May 10 21:27:03 GMT 2007


John Napiorkowski wrote:
> --- Matt S Trout <dbix-class at trout.me.uk> wrote:
> =

>> On Thu, May 10, 2007 at 11:10:49AM -0700, John
>> Napiorkowski wrote:
>>> Hi,
>>>
>>> I may have an issue with the way Row.pm's
>> set_column
>>> method performs it's comparison with possible old
>>> values for the purposes of marking a column dirty.
>>>
>>> I'm running a filter using DBIx::Class::Validation
>> to
>>> try and guess a reasonable datetime object out of
>>> whatever the user submits to a form.  I noticed
>> that
>>> when you update a column $Row->set_column does a
>>> comparison to any old values for the purposes of
>>> marking something dirty.
>>>
>>> However if the old value is a string and the new
>> one
>>> is a DateTime object I get the following error:
>>>
>>> "A DateTime object can only be compared to another
>>> DateTime object (DateTime=3DHASH(0xab3854c),
>> tomorrow)."
>>
>> That should never happen - a column that's inflated
>> to a datetime will
>> have an accessor that calls set_inflated_column, not
>> set_column - which will
>> deflate the value, thus resulting in the comparison
>> being made between two
>> strings.
>>
>> This is why you should almost always use the
>> accessor methods rather than
>> calling set_column directly - it's a public method
>> primarily for subclassing
>> purposes, not for you to call because you've
>> forgotten $obj->$col($val)
>> works.
> =

> The code I have dies on ->create_related(...) because
> the DBIx::Class::Validation profile I have defines a
> filter that converts plaintext to a datetime object
> (or tries very hard).  DBIC::Validation automatically
> updates the row if you set that behavior, and it's
> calling set_column.
> =

> I did a quick hack to DBIC::Validation to change:
> =

> $self->set_column($_, $result->valid($_))
>   for ($result->valid);
> =

> To:
> =

> $self->$_($result->valid($_)) for ($result->valid);
> =

> And behold!  That solved the problem!  Thanks Matt. =

> I'll offer a patch to the maintainer of
> DBIC::Validation.
>

Many had tried. All have failed. Buuuwaaaahhaaahhaaaaaaaaa!!!!!!


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 187 bytes
Desc: OpenPGP digital signature
Url : http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20070510/5e=
db18f2/signature.pgp


More information about the Dbix-class mailing list