summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/sync.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-12-08 18:58:03 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-12-08 18:58:03 +0000
commit8693d4b2876e9239cf48bbc42a7ffaa11c01b506 (patch)
tree6438a7f4a319c4e1f25376fb004de6fb73bfd7c0 /lib/sqlalchemy/orm/sync.py
parent78bb82a44b7f382c6cfeab0cfc7f932e68c4de86 (diff)
downloadsqlalchemy-8693d4b2876e9239cf48bbc42a7ffaa11c01b506.tar.gz
- flush() refactor merged from uow_nontree branch r3871-r3885
- topological.py cleaned up, presents three public facing functions which return list/tuple based structures, without exposing any internals. only the third function returns the "hierarchical" structure. when results include "cycles" or "child" items, 2- or 3- tuples are used to represent results. - unitofwork uses InstanceState almost exclusively now. new and deleted lists are now dicts which ref the actual object to provide a strong ref for the duration that they're in those lists. IdentitySet is only used for the public facing versions of "new" and "deleted". - unitofwork topological sort no longer uses the "hierarchical" version of the sort for the base sort, only for the "per-object" secondary sort where it still helps to group non-dependent operations together and provides expected insert order. the default sort deals with UOWTasks in a straight list and is greatly simplified. Tests all pass but need to see if svilen's stuff still works, one block of code in _sort_cyclical_dependencies() seems to not be needed anywhere but i definitely put it there for a reason at some point; if not hopefully we can derive more test coverage from that. - the UOWEventHandler is only applied to object-storing attributes, not scalar (i.e. column-based) ones. cuts out a ton of overhead when setting non-object based attributes. - InstanceState also used throughout the flush process, i.e. dependency.py, mapper.save_obj()/delete_obj(), sync.execute() all expect InstanceState objects in most cases now. - mapper/property cascade_iterator() takes InstanceState as its argument, but still returns lists of object instances so that they are not dereferenced. - a few tricks needed when dealing with InstanceState, i.e. when loading a list of items that are possibly fresh from the DB, you *have* to get the actual objects into a strong-referencing datastructure else they fall out of scope immediately. dependency.py caches lists of dependent objects which it loads now (i.e. history collections). - AttributeHistory is gone, replaced by a function that returns a 3-tuple of added, unchanged, deleted. these collections still reference the object instances directly for the strong-referencing reasons mentiontioned, but it uses less IdentitySet logic to generate.
Diffstat (limited to 'lib/sqlalchemy/orm/sync.py')
-rw-r--r--lib/sqlalchemy/orm/sync.py21
1 files changed, 8 insertions, 13 deletions
diff --git a/lib/sqlalchemy/orm/sync.py b/lib/sqlalchemy/orm/sync.py
index 8132c7e4a..2d6328514 100644
--- a/lib/sqlalchemy/orm/sync.py
+++ b/lib/sqlalchemy/orm/sync.py
@@ -61,7 +61,7 @@ class ClauseSynchronizer(object):
source_column = binary.right
else:
if binary.left in foreign_keys:
- source_column=binary.right
+ source_column = binary.right
dest_column = binary.left
elif binary.right in foreign_keys:
source_column = binary.left
@@ -94,15 +94,10 @@ class SyncRule(object):
"""An instruction indicating how to populate the objects on each
side of a relationship.
- In other words, if table1 column A is joined against table2 column
+ E.g. if table1 column A is joined against table2 column
B, and we are a one-to-many from table1 to table2, a syncrule
would say *take the A attribute from object1 and assign it to the
B attribute on object2*.
-
- A rule contains the source mapper, the source column, destination
- column, destination mapper in the case of a one/many relationship,
- and the integer direction of this mapper relative to the
- association in the case of a many to many relationship.
"""
def __init__(self, source_mapper, source_column, dest_column, dest_mapper=None, issecondary=None):
@@ -123,26 +118,26 @@ class SyncRule(object):
self._dest_primary_key = self.dest_mapper is not None and self.dest_column in self.dest_mapper._pks_by_table[self.dest_column.table] and not self.dest_mapper.allow_null_pks
return self._dest_primary_key
- def execute(self, source, dest, obj, child, clearkeys):
+ def execute(self, source, dest, parent, child, clearkeys):
if source is None:
if self.issecondary is False:
- source = obj
+ source = parent
elif self.issecondary is True:
source = child
if clearkeys or source is None:
value = None
clearkeys = True
else:
- value = self.source_mapper._get_attr_by_column(source, self.source_column)
+ value = self.source_mapper._get_state_attr_by_column(source, self.source_column)
if isinstance(dest, dict):
dest[self.dest_column.key] = value
else:
if clearkeys and self.dest_primary_key():
- raise exceptions.AssertionError("Dependency rule tried to blank-out primary key column '%s' on instance '%s'" % (str(self.dest_column), mapperutil.instance_str(dest)))
+ raise exceptions.AssertionError("Dependency rule tried to blank-out primary key column '%s' on instance '%s'" % (str(self.dest_column), mapperutil.state_str(dest)))
if logging.is_debug_enabled(self.logger):
- self.logger.debug("execute() instances: %s(%s)->%s(%s) ('%s')" % (mapperutil.instance_str(source), str(self.source_column), mapperutil.instance_str(dest), str(self.dest_column), value))
- self.dest_mapper._set_attr_by_column(dest, self.dest_column, value)
+ self.logger.debug("execute() instances: %s(%s)->%s(%s) ('%s')" % (mapperutil.state_str(source), str(self.source_column), mapperutil.state_str(dest), str(self.dest_column), value))
+ self.dest_mapper._set_state_attr_by_column(dest, self.dest_column, value)
SyncRule.logger = logging.class_logger(SyncRule)