diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-07-24 12:37:48 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-07-24 12:37:48 -0400 |
| commit | 0cc357c6caf8f5d4e33e3dedd799beeca0304518 (patch) | |
| tree | 646688445ff77f13f4b45af3a4b6460a4f3de794 /lib/sqlalchemy | |
| parent | 5abc41127890e92facab2dc202f365a374d2394b (diff) | |
| download | sqlalchemy-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.py | 17 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/properties.py | 7 |
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): |
