From 65da266daaaaed26c5d141bad1eda2600c597da4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 21 Feb 2008 21:41:53 +0000 Subject: [PATCH] - preventive code against a potential lost-reference bug in flush() --- CHANGES | 5 ++++- lib/sqlalchemy/orm/unitofwork.py | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 988c0403d1..c9030a6ba8 100644 --- a/CHANGES +++ b/CHANGES @@ -30,7 +30,10 @@ CHANGES query.join(Company.employees.of_type(Engineer)). filter(Engineer.name=='foo') - + + - preventive code against a potential lost-reference + bug in flush() + 0.4.4 ------ diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 0f87d73087..cd6254b22f 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -134,9 +134,13 @@ class UnitOfWork(object): if hasattr(state, 'insert_order'): delattr(state, 'insert_order') - - self.identity_map[state.dict['_instance_key']] = state.obj() - state.commit_all() + + o = state.obj() + # prevent against last minute dereferences of "dirty" + # objects TODO: identify a code path where state.obj() is None + if o is not None: + self.identity_map[state.dict['_instance_key']] = o + state.commit_all() # remove from new last, might be the last strong ref self.new.pop(state, None) -- 2.47.3