myobie,

> If I change @original_attributes ||= {} to @original_attributes || {}
> in lib/dm-core/resource.rb, I no longer get this error - so it is
> definitly the problem that somehow @original_attributes is getting
> frozen.
>
> I cannot find anywhere in dm-core that would cause this. Does anyone
> more familiar with this know why this would happen?
>
> For now, I am going with that small change which should be fine
> (should), but I don't like the idea that the instance variable is
> being frozen when I don't see a #freeze method happening anywhere near
> there. I might have to override the freeze method and log when it is
> used or something.

Resource#freeze is used in a couple of places, one of which I think is
causing this problem.

One case is when you load a Resource, but you don't specify that the
key be retrieved from the adapter.  The resulting Resource can't be
persisted back into the datastore without a key, so it's marked as
read-only.  In 0.9 we did this by setting a @readonly ivar to true,
but in 0.10 I thought it would be a good idea to *really* make it read-
only using Object#freeze.

While I had good intentions with this change, and technically it is
closer to what we want, it has a few drawbacks.  One of the largest
ones is that DM memoizes some values internally on first-access (like
@original_attributes), but if the Resource instance is frozen, then
the ivar cannot be set.

I think I'm going to back out of this change, and add the @readonly
ivar back in, along with Resource#readonly?.  I'll also make it so
that attempts to use mutators and persistence on the Resource raises
an exception.  Without this change we're going to have to put logic
branches everyplace that we memoize values, and make sure it behaves
differently when frozen or not (there's already one place we do this
and I don't like it).

Does anyone see any drawback to this solution?

--

Dan
(dkubb)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to