summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-07-24 12:37:48 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-07-24 12:37:48 -0400
commit0cc357c6caf8f5d4e33e3dedd799beeca0304518 (patch)
tree646688445ff77f13f4b45af3a4b6460a4f3de794 /lib/sqlalchemy
parent5abc41127890e92facab2dc202f365a374d2394b (diff)
downloadsqlalchemy-0cc357c6caf8f5d4e33e3dedd799beeca0304518.tar.gz
- Fixed regression from 0.6 where Session.add()
against an object which contained None in a collection would raise an internal exception. Reverted this to 0.6's behavior which is to accept the None but obviously nothing is persisted. Ideally, collections with None present or on append() should at least emit a warning, which is being considered for 0.8. [ticket:2205]
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/orm/attributes.py17
-rw-r--r--lib/sqlalchemy/orm/properties.py7
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index c72151948..a24348c86 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -722,8 +722,12 @@ class CollectionAttributeImpl(AttributeImpl):
if self.key in state.committed_state:
original = state.committed_state[self.key]
if original is not NO_VALUE:
- current_states = [(instance_state(c), c) for c in current]
- original_states = [(instance_state(c), c) for c in original]
+ current_states = [((c is not None) and
+ instance_state(c) or None, c)
+ for c in current]
+ original_states = [((c is not None) and
+ instance_state(c) or None, c)
+ for c in original]
current_set = dict(current_states)
original_set = dict(original_states)
@@ -1114,8 +1118,13 @@ class History(tuple):
elif original is _NO_HISTORY:
return cls((), list(current), ())
else:
- current_states = [(instance_state(c), c) for c in current]
- original_states = [(instance_state(c), c) for c in original]
+
+ current_states = [((c is not None) and instance_state(c) or None, c)
+ for c in current
+ ]
+ original_states = [((c is not None) and instance_state(c) or None, c)
+ for c in original
+ ]
current_set = dict(current_states)
original_set = dict(original_states)
diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py
index e7f473b67..494d94bb0 100644
--- a/lib/sqlalchemy/orm/properties.py
+++ b/lib/sqlalchemy/orm/properties.py
@@ -818,6 +818,13 @@ class RelationshipProperty(StrategizedProperty):
if instance_state in visited_states:
continue
+ if c is None:
+ # would like to emit a warning here, but
+ # would not be consistent with collection.append(None)
+ # current behavior of silently skipping.
+ # see [ticket:2229]
+ continue
+
instance_dict = attributes.instance_dict(c)
if halt_on and halt_on(instance_state):