[CDBI] construct sucks.

Matt S Trout dbix-class at trout.me.uk
Sun Aug 27 20:18:50 BST 2006


Ryan Tate wrote:
> Uh, has anyone else ever noticed that ->construct kind of blows rocks?
> 
> Specifically, if you ->construct an object that's already in the
> LiveObject index, CDBI will throw away perfectly good fresh data about
> the object -- columns not present at all in the indexed version -- and
> just hand you whatever incomplete object it has sitting around?
> 
> This behavior I discovered using 0.96, but it seems to have been
> carried forward to the latest CDBI, based on eyeballing the code.
> 
> This will bite you if you have an essential column inflating to a
> particular object, then you try and construct that object after
> retrieving it using custom SQL. In my case, I have two classes related
> many_to_many, but in one class each object also keeps a reference to
> one particular object from the other class because the one is special
> among the many related from that class. This particular object was
> auto-inflating but I needed to construct it later from some custom SQL
> retrieving all the other related objects (and some special info stored
> in the mapping table).
> 
> Anyway, I'll probably code a patch, if only for myself, and perhaps
> file it with an RT bug, unless someone knows this to be By Design.
> Also, I'd love to hear how DBIx::Class handles this.

We used a really simple solution: Don't have a Live Object Index. It's never 
caused me anything but pain, and it only really provides the illusion of 
consistency anyway since other processes may be modifying the database as 
well, so it tends to turn out simpler to code defensively in the first place 
(and with suitable use of prefetch query numbers can still be kept fairly low 
anyway)

Short-term caching of primary and unique key lookups is being looked into, but 
if we do implement it it'll likely be very much designed as a short-term cache 
- think either a single web request or a single transaction, where you can 
either assume consistency or you're in a situation where not getting a fresher 
copy of a given piece of data within the timeframe isn't a big deal.

-- 
      Matt S Trout       Offering custom development, consultancy and support
   Technical Director    contracts for Catalyst, DBIx::Class and BAST. Contact
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

+ Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +



More information about the ClassDBI mailing list