It seems there must be something I'm missing here, so hopefully other  
sets of eyes will spot an obvious mistake.

I have a series of objects that may-or-may not be persistent: some  
will be created and stored to a db, some will be retrieved from the  
db, maybe modified and updated, others will never go anywhere near  
the db. (I have a series of programs using the same objects, only  
some of which need to interact with the db.) However, I'm

A simple test case. Given this code:

class Sample (object):
        def __init__ (self, id=None, title=None, description=None):
                self.id = id
                self.title = title
                self.description = description

class Conn (object):
        def __init__ (self):    
                conn_uri = CONN_URI_TMPL % TESTDB_CONNINFO
                self.SA_ENGINE = create_engine (conn_uri)
                self.SA_METADATA = MetaData (conn_uri)
                self.SA_ENGINE.echo = True
                Session = sessionmaker (bind=self.SA_ENGINE)
                self.SA_SESSION = Session()
                self.SA_QUERY = self.SA_SESSION.query

                self.SAMPLETABLE = Table ('samples', self.SA_METADATA,
                        Column ('id', Unicode(32), primary_key=True),
                        Column ('title', Unicode(32)),
                        Column ('description', Unicode(32)),
                )
                self.SA_METADATA.create_all (checkfirst=True)
                clear_mappers()
                mapper (Sample, self.SAMPLETABLE)

Sample is the class I'd like to be able to persist if needed. Conn  
just encapsulates the connection for test purposes. Now if I do this:

c = Conn()
s1 = Sample()
s1.id = 'foo'
c.SA_SESSION.save_or_update (s1)
c.SA_SESSION.flush()

all is well.  But if I create the Sample before the connection, it  
doesn't work:

s1 = Sample()
s1.id = 'foo'
c = Conn()
c.SA_SESSION.save_or_update (s1)
c.SA_SESSION.flush()

....
AttributeError: 'ColumnProperty' object has no attribute 'key'

So, how can I persist an object constructed before the connection is  
established? Or is it necessary to do all work either within or  
without of the context of a session?

Thanks

--
Dr Paul-Michael Agapow: VieDigitale / Inst. for Animal Health
[EMAIL PROTECTED] / [EMAIL PROTECTED]




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to