0.5: attribute gets None after commit
Issue #1272
resolved
# The last line (assert) fails with both 0.5rc4 and todays Mercurial trunk.
# It does not fail with 0.4.6, 0.4.7.
# Can only be reproduced with weak_identity_map=False (see sessionmaker line)
# Environment: CPython 2.5 on AMD64 Linux
# EMail: tmp2@reifenberg.de
from sqlalchemy import *
from sqlalchemy.orm import *
import sqlalchemy; print sqlalchemy.__version__
MYSQLENGINE = "MyISAM" # same effect with InnoDB
# same effect with sqlite and MySQL
#engineStr = "mysql://spam@localhost/satest1"
engineStr = 'sqlite:///:memory:'
db = create_engine(engineStr)
metadata = MetaData(db)
a_table = Table("edgecls", metadata,
Column("id", Integer, primary_key=True),
mysql_engine=MYSQLENGINE,
)
b_table = Table("biobjedge", metadata,
Column("id", Integer, primary_key=True),
Column("cls_id", Integer, ForeignKey("edgecls.id"), nullable=False),
Column("inferfrom_id", Integer, ForeignKey("biobjedge.id"), default=None),
mysql_engine=MYSQLENGINE,
)
metadata.drop_all()
metadata.create_all() # scheint nix zu schaden, wenn sie schon existieren
class AClass(object): pass
class BClass(object):
def __init__(self, edgecls, id=None, inferfrom=None):
self.id = id
self._inferfrom = inferfrom
self._edgecls = edgecls
mapper(AClass,a_table)
mapper(BClass,b_table,properties={
"_edgecls":relation(
AClass,
backref=backref("edges"),
),
"_inferfrom":relation(
BClass,
uselist=False,
remote_side=b_table.c.id,
backref=backref("inferreds"),
)
})
orms = sessionmaker(weak_identity_map=False)() #if True,0.5 does not fail
ec_7 = AClass()
orms.save(ec_7)
binstance1 = BClass(edgecls=ec_7)
binstance2 = BClass(edgecls=ec_7)
orms.commit() #without this commit, 0.5 does not fail below
binstance2._inferfrom=binstance1
assert binstance2._inferfrom == binstance1
orms.commit()
assert binstance2._inferfrom == binstance1, "was:%s"%(binstance2._inferfrom) # fails with 0.5
Comments (2)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.5.0 (automated comment)
- Log in to comment
thanks for the test case, ec344ebf72a6f361a192a61e35d8f8491ed41889.