- sending a selectable to an IN no longer creates a "union" out of multiple
selects; only one selectable to an IN is allowed now (make a union yourself
if union is needed; explicit better than implicit, dont guess, etc.)
-
+- improved support for disabling save-update cascade via cascade="none" etc.
0.3.1
- Engine/Pool:
- some new Pool utility classes, updated docs
if (hasattr(obj, '_instance_key') and not self.identity_map.has_key(obj._instance_key)) or \
(not hasattr(obj, '_instance_key') and obj not in self.new):
raise InvalidRequestError("Instance '%s' is not attached or pending within this session" % repr(obj))
-
+
+ def _is_valid(self, obj):
+ if (hasattr(obj, '_instance_key') and not self.identity_map.has_key(obj._instance_key)) or \
+ (not hasattr(obj, '_instance_key') and obj not in self.new):
+ return False
+ else:
+ return True
+
def register_attribute(self, class_, key, uselist, **kwargs):
attribute_manager.register_attribute(class_, key, uselist, **kwargs)
registration is entered for the object."""
#print "REGISTER", repr(obj), repr(getattr(obj, '_instance_key', None)), str(isdelete), str(listonly)
- # things can get really confusing if theres duplicate instances floating around,
- # so make sure everything is OK
- self.uow._validate_obj(obj)
+ # if object is not in the overall session, do nothing
+ if not self.uow._is_valid(obj):
+ return
mapper = object_mapper(obj)
self.mappers.add(mapper)
class SessionTest(AssertMixin):
def setUpAll(self):
tables.create()
- tables.data()
def tearDownAll(self):
tables.drop()
def tearDown(self):
assert user in s
assert user not in s.dirty
+ def test_no_save_cascade(self):
+ mapper(Address, addresses)
+ mapper(User, users, properties=dict(
+ addresses=relation(Address, cascade="none", backref="user")
+ ))
+ s = create_session()
+ u = User()
+ s.save(u)
+ a = Address()
+ u.addresses.append(a)
+ assert u in s
+ assert a not in s
+ s.flush()
+ s.clear()
+ assert s.query(User).selectone().user_id == u.user_id
+ assert s.query(Address).selectfirst() is None
+
+ clear_mappers()
+
+ tables.delete()
+ mapper(Address, addresses)
+ mapper(User, users, properties=dict(
+ addresses=relation(Address, cascade="all", backref=backref("user", cascade="none"))
+ ))
+
+ s = create_session()
+ u = User()
+ a = Address()
+ a.user = u
+ s.save(a)
+ assert u not in s
+ assert a in s
+ s.flush()
+ s.clear()
+ assert s.query(Address).selectone().address_id == a.address_id
+ assert s.query(User).selectfirst() is None
class OrphanDeletionTest(AssertMixin):