Objects with (re)defined __nonzero__ are dropped from a session after commit

Issue #836 resolved
Former user created an issue

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)

  1. Mike Bayer repo owner

    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.

  2. Log in to comment