diff --git a/rattail/importing/sqlalchemy.py b/rattail/importing/sqlalchemy.py index c466987a7ee8aa7cb7fcbbfc669e962170730a41..3b34efd0b07064075f010b933aeeb90bcb5b4988 100644 --- a/rattail/importing/sqlalchemy.py +++ b/rattail/importing/sqlalchemy.py @@ -127,7 +127,6 @@ class ToSQLAlchemy(Importer): truly delete and expunge the local object from the session. """ self.session.delete(obj) - self.session.expunge(obj) return True def cache_model(self, model, **kwargs): diff --git a/rattail/tests/importing/test_sqlalchemy.py b/rattail/tests/importing/test_sqlalchemy.py index c5674c97edb3b02ef45860dae40ab86453b0350e..6500f96af8785c61e7445542e6d4b0f4d58cf6ff 100644 --- a/rattail/tests/importing/test_sqlalchemy.py +++ b/rattail/tests/importing/test_sqlalchemy.py @@ -102,8 +102,8 @@ class TestToSQLAlchemy(TestCase): def test_create_object(self): importer = self.make_importer(key='id', session=self.session) widget = importer.create_object((42,), {'id': 42, 'description': "Latest Widget"}) - self.assertFalse(self.session.new or self.session.dirty or self.session.deleted) # i.e. has been flushed - self.assertIn(widget, self.session) # therefore widget has been flushed and would be committed + self.assertIn(widget, self.session) + self.assertIn(widget, self.session.new) self.assertEqual(widget.id, 42) self.assertEqual(widget.description, "Latest Widget") @@ -112,7 +112,9 @@ class TestToSQLAlchemy(TestCase): self.assertIn(widget, self.session) importer = self.make_importer(session=self.session) self.assertTrue(importer.delete_object(widget)) - self.assertNotIn(widget, self.session) + self.assertIn(widget, self.session) + self.assertIn(widget, self.session.deleted) + self.session.flush() self.assertIsNone(self.session.query(Widget).get(1)) def test_cache_model(self):