summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-04-23 12:03:54 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-04-23 12:03:54 -0400
commit54017d9de202ed67072a352ce2f6dbfd74bf48f3 (patch)
treea632045bd8a5e7d5932d69d5f436bc27f1b9788d /lib/sqlalchemy/orm/attributes.py
parent8f35f7a803c67f4ab0620686592a021a24e4b331 (diff)
parentf7bb3b17e6df09caa56c20c722364fc52edf7afc (diff)
downloadsqlalchemy-54017d9de202ed67072a352ce2f6dbfd74bf48f3.tar.gz
merge patch for [ticket:2208]. This still needs documentation.
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index ec0b84a60..d75682443 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -16,7 +16,7 @@ defines a large part of the ORM's interactivity.
import operator
from operator import itemgetter
-from sqlalchemy import util, event, exc as sa_exc
+from sqlalchemy import util, event, exc as sa_exc, inspection
from sqlalchemy.orm import interfaces, collections, events, exc as orm_exc
@@ -94,7 +94,6 @@ PASSIVE_NO_FETCH_RELATED = PASSIVE_OFF ^ RELATED_OBJECT_OK
PASSIVE_ONLY_PERSISTENT = PASSIVE_OFF ^ NON_PERSISTENT_OK
-
class QueryableAttribute(interfaces.PropComparator):
"""Base class for class-bound attributes. """
@@ -164,6 +163,10 @@ class QueryableAttribute(interfaces.PropComparator):
return self.comparator.property
+@inspection._inspects(QueryableAttribute)
+def _get_prop(source):
+ return source.property
+
class InstrumentedAttribute(QueryableAttribute):
"""Class bound instrumented attribute which adds descriptor methods."""
@@ -201,11 +204,13 @@ def create_proxied_attribute(descriptor):
"""
- def __init__(self, class_, key, descriptor, comparator,
+ def __init__(self, class_, key, descriptor, property_,
+ comparator,
adapter=None, doc=None):
self.class_ = class_
self.key = key
self.descriptor = descriptor
+ self.original_property = property_
self._comparator = comparator
self.adapter = adapter
self.__doc__ = doc
@@ -542,7 +547,7 @@ class ScalarAttributeImpl(AttributeImpl):
if self.dispatch.remove:
self.fire_remove_event(state, dict_, old, None)
- state.modified_event(dict_, self, old)
+ state._modified_event(dict_, self, old)
del dict_[self.key]
def get_history(self, state, dict_, passive=PASSIVE_OFF):
@@ -562,7 +567,7 @@ class ScalarAttributeImpl(AttributeImpl):
if self.dispatch.set:
value = self.fire_replace_event(state, dict_,
value, old, initiator)
- state.modified_event(dict_, self, old)
+ state._modified_event(dict_, self, old)
dict_[self.key] = value
def fire_replace_event(self, state, dict_, value, previous, initiator):
@@ -721,7 +726,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
for fn in self.dispatch.remove:
fn(state, value, initiator or self)
- state.modified_event(dict_, self, value)
+ state._modified_event(dict_, self, value)
def fire_replace_event(self, state, dict_, value, previous, initiator):
if self.trackparent:
@@ -733,7 +738,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
for fn in self.dispatch.set:
value = fn(state, value, previous, initiator or self)
- state.modified_event(dict_, self, previous)
+ state._modified_event(dict_, self, previous)
if self.trackparent:
if value is not None:
@@ -816,7 +821,7 @@ class CollectionAttributeImpl(AttributeImpl):
for fn in self.dispatch.append:
value = fn(state, value, initiator or self)
- state.modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NEVER_SET, True)
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), state, True)
@@ -824,7 +829,7 @@ class CollectionAttributeImpl(AttributeImpl):
return value
def fire_pre_remove_event(self, state, dict_, initiator):
- state.modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NEVER_SET, True)
def fire_remove_event(self, state, dict_, value, initiator):
if self.trackparent and value is not None:
@@ -833,13 +838,13 @@ class CollectionAttributeImpl(AttributeImpl):
for fn in self.dispatch.remove:
fn(state, value, initiator or self)
- state.modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NEVER_SET, True)
def delete(self, state, dict_):
if self.key not in dict_:
return
- state.modified_event(dict_, self, NEVER_SET, True)
+ state._modified_event(dict_, self, NEVER_SET, True)
collection = self.get_collection(state, state.dict)
collection.clear_with_event()
@@ -866,7 +871,7 @@ class CollectionAttributeImpl(AttributeImpl):
value = self.fire_append_event(state, dict_, value, initiator)
assert self.key not in dict_, \
"Collection was loaded during event handling."
- state.get_pending(self.key).append(value)
+ state._get_pending_mutation(self.key).append(value)
else:
collection.append_with_event(value, initiator)
@@ -879,7 +884,7 @@ class CollectionAttributeImpl(AttributeImpl):
self.fire_remove_event(state, dict_, value, initiator)
assert self.key not in dict_, \
"Collection was loaded during event handling."
- state.get_pending(self.key).remove(value)
+ state._get_pending_mutation(self.key).remove(value)
else:
collection.remove_with_event(value, initiator)
@@ -935,7 +940,7 @@ class CollectionAttributeImpl(AttributeImpl):
return
# place a copy of "old" in state.committed_state
- state.modified_event(dict_, self, old, True)
+ state._modified_event(dict_, self, old, True)
old_collection = getattr(old, '_sa_adapter')
@@ -956,12 +961,12 @@ class CollectionAttributeImpl(AttributeImpl):
state.commit(dict_, [self.key])
- if self.key in state.pending:
+ if self.key in state._pending_mutations:
# pending items exist. issue a modified event,
# add/remove new items.
- state.modified_event(dict_, self, user_data, True)
+ state._modified_event(dict_, self, user_data, True)
- pending = state.pending.pop(self.key)
+ pending = state._pending_mutations.pop(self.key)
added = pending.added_items
removed = pending.deleted_items
for item in added:
@@ -1408,5 +1413,5 @@ def flag_modified(instance, key):
"""
state, dict_ = instance_state(instance), instance_dict(instance)
impl = state.manager[key].impl
- state.modified_event(dict_, impl, NO_VALUE)
+ state._modified_event(dict_, impl, NO_VALUE)