Objects with (re)defined __nonzero__ are dropped from a session after commit
Issue #836
resolved
Objects whith bool(obj) == False are dropped from session after commit. There is nothing about it in documentation, and no warnings or exceptions raised. There is test code:
from sqlalchemy import *
from sqlalchemy.orm import *
import pickle
engine = create_engine('sqlite://')
metadata = MetaData()
obj = Table('obj', metadata,
Column('id', Integer, primary_key=True),
Column('data', Unicode(32)),
)
class Obj(object):
def __nonzero__(self):
return False
mapper(Obj, obj)
metadata.create_all(bind=engine)
session = create_session(bind=engine)
o = Obj()
o.data = 'test'
session.begin()
session.save(o)
session.commit()
assert o in session
Comments (2)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.4.xx (automated comment)
- Log in to comment
going to make this a dupe of
#676. nonzero is probably easier to fix than hash, since i dont think we should be doing any "if obj: <foo>" anywhere.