I have also experienced problems with this exception.Here is a simple
example:

import sqlalchemy
import sqlalchemy.orm as orm

engine = sqlalchemy.create_engine('sqlite:///:memory:', echo=True)
metadata = sqlalchemy.MetaData()

users_table = sqlalchemy.Table('users', metadata,
                    sqlalchemy.Column('id', sqlalchemy.Integer,
primary_key=True),
                    sqlalchemy.Column('name', sqlalchemy.String),
                    sqlalchemy.Column('fullname', sqlalchemy.String),
                    sqlalchemy.Column('password', sqlalchemy.String)
                    )

metadata.create_all(engine)
metadata.bind = engine

class User(object):
    pass

orm.mapper(User, users_table)

MySession = orm.sessionmaker(autoflush=True, autocommit=False)
session = MySession()

user = User()
user.name = "ed"
user.fullname = "Ed Jones"
user.password = "password"

session.add(user)
session.commit()
session.close()

print user.name


The last print statement fails with the "attribute refresh operation
cannot proceed" exception with the 0.5.2 version. The corresponent
code for 0.4.5 works fine.

What I would like to be able to is to keep on working with detached
objects like the user object in the code above , in a manner where the
objects attribute values are the same as they were when the session
was closed, i.e. without further database queries (and certainly
without exceptions!). If there was some way to ensure that all
database attributes on the object were loaded but not modifiable, it
could solve the problem. In my current application I use the
get_session extension to return the ScopedSession instance in order to
ensure that I can access attributes but I would prefer that the
objects were properly detached but still funcionable.

Any ideas as to what I could do?




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to