I had this bug with 0.2.7 and then upgraded to 0.2.8 and it is still there.

I've attached a test case to show the issue.  Basically, when you have
a deferred group, only the 1st column accessed gets set.  The other
columns are deferred and later queried properly, but they are not set
as attribute values of the mapped class.

example:

table with fields id and then def1, def2, def3 all of group 'deferreds'

t=....get(id=1)
t.def1
# at this point def1 is queried and set.  def2 and def3 were selected,
but not set.

Here is the output of my test case:

original object:
normal: normal text
def1: deferred text1
def2: deferred text2
1st select w/ def1 accessed 1st:
normal: normal text
def1: deferred text1
def2: None
2nd select w/ def2 accessed 1st:
normal: normal text
def1: None
def2: deferred text2

I am using postgresql.  Here is the sql logged when my 1st deferred
column is accessed:
SELECT test.def2 AS test_def2, test.def1 AS test_def1
       FROM test
       WHERE test.id = 1
(So both deferred columns are being selected, but only the 1st, the
accessed column, is set on the class)

Next I'll look for the sqlalchemy code that needs tweaked.  Perhaps
someone can point me the right direction faster than I can find it
myself though.

Thanks
Dennis
from sqlalchemy import *

engine = create_engine ( 'postgres://localhost/test' )

dbmeta = BoundMetaData(engine)


test = Table ( 'test', dbmeta ,
	Column ( 'id', Integer, primary_key=True, nullable=False ),
	Column ( 'normal', VARCHAR(20) ),
	Column ( 'def1', VARCHAR(20) ),
	Column ( 'def2', VARCHAR(20) ) )

class Test(object):
	def _print(self):
		print "normal: %s" % self.normal
		print "def1: %s" % self.def1
		print "def2: %s" % self.def2

mapper(Test,test,properties={'def1':deferred(test.c.def1,group='deferreds'),'def2':deferred(test.c.def2,group='deferreds')})



dbmeta.drop_all()
dbmeta.create_all()


s=create_session()

# test now

t=Test()
t.normal='normal text'
t.def1='deferred text1'
t.def2='deferred text2'

s.save(t)
s.flush()
id=t.id

print 'original object:'
t._print()

s.clear()

# select
print '1st select w/ def1 accessed 1st:'
t=s.query(Test).get( id )
d1=t.def1
t._print()

s.clear()

print '2nd select w/ def2 accessed 1st:'
t=s.query(Test).get( id )
d2=t.def2
t._print()


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to