it should raise an error when you go to delete() it because sp2 is not persistent; it makes no sense to call delete on it.
On Jul 21, 2006, at 8:03 PM, Brett wrote: > > The SA trac is down so I'll post this here so I don't forget about. I > would expect the last line of this test to print None, instead it > prints > out the species name, Maxillaria test. It seems like if you set an > attribute on an object after it has been deleted it somehow becomes > undeleted. I haven't looked over the code in SA, is this intentional? > > ---------- > > from sqlalchemy import * > from sqlalchemy.orm.session import * > > uri = 'sqlite:///:memory:' > global_connect(uri) > > species_table = Table('species', > Column('id', Integer, primary_key=True), > Column('sp', String), > Column('genus_id', Integer, ForeignKey('genus.id')), > Column('default_vernacular_name_id', Integer)) > # ForeignKey('vernacular_name.id'))) > > vernacular_name_table = Table('vernacular_name', > Column('id', Integer, primary_key=True), > Column('name', Unicode(128), > unique='vn_index'), > Column('language', Unicode(128), > unique='vn_index'), > Column('species_id', Integer, > ForeignKey('species.id'), > unique='vn_index')) > > genus_table = Table('genus', > Column('id', Integer, primary_key=True), > Column('genus', String)) > > class Genus(object): > def __str__(self): > return self.genus > > class Species(object): > def __str__(self): > return '%s %s' % (self.genus, self.sp) > > class VernacularName(object): > def __str__(self): > return self.name > > mapper(Species, species_table) > mapper(Genus, genus_table, > properties = {'species': relation(Species, > backref=backref('genus', lazy=False), > order_by=['sp'])}) > mapper(VernacularName, vernacular_name_table) > > default_metadata.create_all() > genus_table.insert().execute({'genus': 'Maxillaria'}) > species_table.insert().execute({'genus_id': 1, 'sp': 'sp'}) > > # where the action is > session = create_session() > sp = session.query(Species).get_by(id=1) > assert sp is not None > sp2 = Species() > sp2.genus_id = 1 > session.save(sp2) > session.delete(sp2) > sp2.sp = 'test' > session.flush() > print session.query(Species).get_by(id=2) > > ---------- > > > > > > ---------------------------------------------------------------------- > --- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to > share your > opinions on IT & business topics through brief surveys -- and earn > cash > http://www.techsay.com/default.php? > page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Sqlalchemy-users mailing list > Sqlalchemy-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users