← Back to team overview

openstack team mailing list archive

Re: using objects returned from DB layer

 

On Dec 15, 2011, at 1:10 AM, Chris Behrens wrote:

> 
> I've seen a number of patches lately that have code like this:
> 
> instance = db.instance_get(...)
> instance_uuid = instance.uuid
> 
> instead of:
> 
> instance_uuid = instance['uuid']
> 
> There's a mix of usage throughout the code, and I know some people are just matching the surrounding code.  But, in a number of cases, I've asked for these to be corrected to the latter, on assumption that the DB layer will be returning dictionaries at some point vs the models.  It also pushes the code towards consistent usage.  But I might be the only Nova Core member looking at this and/or maybe my assumption is wrong.
> 

Actually, what we should be working to is using plain python model objects, and having the sqlalchemy layer use it's mapper functionality (separated from the models) to map db rows to those models. THis will allow any persistence  layer to map to the same model objects, and allow us to have actual, object-oriented design in our code. (like real methods, where appropriate)  This would suggest the dot notation, although making a python  model class support a dict interface for backwards compatability whilst things are refactored is easy to do.  

> So, I ask here:  Should Nova Core make an effort to reject patches with the former format?   Or did I miss any DB layer plans where the former format is now preferred

Myself, and 0x44 discussed this at the db team meetings. We've been writing some blueprints on this. 




> - Chris
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Mailing list: https://launchpad.net/~openstack
> Post to     : openstack@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~openstack
> More help   : https://help.launchpad.net/ListHelp

--
	Monsyne M. Dragon
	OpenStack/Nova 
	cell 210-441-0965
	work x 5014190



Follow ups

References