Hi all,
I'm getting an unexpected ObjectDeletedError. The following code shows
the problem (on SA 0.5.6, with both sqlite and postgresql):

from sqlalchemy import *
from sqlalchemy import orm

# Usual stuff...
m = MetaData()
t = Table("test", m,
          Column("id", Integer, primary_key=True),
          Column("description", String))
class T(object): pass

# Plain mapping, no relations
orm.mapper(T, t)

# More initialization stuff
Session = orm.sessionmaker(autocommit=True, autoflush=False)
e = create_engine("sqlite:///")
m.bind = e
Session.configure(bind=e)
m.create_all()

# Insert objects...
s = Session()
for x in range(1, 6):
    t = T()
    t.id = x
    t.description = "Object %s" % x
    s.add(t)
s.flush()

# ...now try to change the ID of one of them...
o = s.query(T).get(2)
o.id = 10
o.description = "Changed"
s.flush()

On the flush() I get:

Traceback (most recent call last):
  File "test.py", line 34, in <module>
    s.flush()
  File "/Library/Python/2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/
sqlalchemy/orm/session.py", line 1356, in flush
    self._flush(objects)
.....................................
[CUT]
.....................................
  File "/Library/Python/2.6/site-packages/SQLAlchemy-0.5.6-py2.6.egg/
sqlalchemy/orm/mapper.py", line 1864, in _load_scalar_attributes
    raise exc.ObjectDeletedError("Instance '%s' has been deleted." %
state_str(state))
sqlalchemy.orm.exc.ObjectDeletedError: Instance '<T at 0x1022ed0>' has
been deleted.

The documentation states: "As of SQLAlchemy 0.4.2, the primary key
attributes of an instance can be changed freely" (and actually a
similar code works on SA 0.4.4), so is it a bug or I'm missing
something?

Thanks
Antonio
--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to