[Sqlalchemy-commits] [1370] sqlalchemy/branches/schema/test: took out get(*ident) style of argument,
Brought to you by:
zzzeek
From: <co...@sq...> - 2006-05-01 23:08:06
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:':';} #msg dl, #msg dt, #msg ul, #msg li { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1370] sqlalchemy/branches/schema/test: took out get(*ident) style of argument, its now a scalar or tuple</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1370</dd> <dt>Author</dt> <dd>zzzeek</dd> <dt>Date</dt> <dd>2006-05-01 18:07:48 -0500 (Mon, 01 May 2006)</dd> </dl> <h3>Log Message</h3> <pre>took out get(*ident) style of argument, its now a scalar or tuple</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormmapperpy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormpropertiespy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormquerypy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py</a></li> <li><a href="#sqlalchemybranchesschemalibsqlalchemyormsessionpy">sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py</a></li> <li><a href="#sqlalchemybranchesschematestobjectstorepy">sqlalchemy/branches/schema/test/objectstore.py</a></li> <li><a href="#sqlalchemybranchesschematesttablespy">sqlalchemy/branches/schema/test/tables.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemybranchesschemalibsqlalchemyormmapperpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/mapper.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -274,9 +274,9 @@ </span><span class="cx"> self._query = querylib.Query(self) </span><span class="cx"> return self._query </span><span class="cx"> </span><del>- def get(self, *ident, **kwargs): </del><ins>+ def get(self, ident, **kwargs): </ins><span class="cx"> """calls get() on this mapper's default Query object.""" </span><del>- return self.query().get(*ident, **kwargs) </del><ins>+ return self.query().get(ident, **kwargs) </ins><span class="cx"> </span><span class="cx"> def _get(self, key, ident=None, reload=False): </span><span class="cx"> return self.query()._get(key, ident=ident, reload=reload) </span><span class="lines">@@ -464,13 +464,13 @@ </span><span class="cx"> result = [result] + otherresults </span><span class="cx"> return result </span><span class="cx"> </span><del>- def identity_key(self, *primary_key): </del><ins>+ def identity_key(self, primary_key): </ins><span class="cx"> """returns the instance key for the given identity value. this is a global tracking object used by the Session, and is usually available off a mapped object as instance._instance_key.""" </span><del>- return sessionlib.get_id_key(tuple(primary_key), self.class_, self.entity_name) </del><ins>+ return sessionlib.get_id_key(util.to_list(primary_key), self.class_, self.entity_name) </ins><span class="cx"> </span><span class="cx"> def instance_key(self, instance): </span><span class="cx"> """returns the instance key for the given instance. this is a global tracking object used by the Session, and is usually available off a mapped object as instance._instance_key.""" </span><del>- return self.identity_key(*self.identity(instance)) </del><ins>+ return self.identity_key(self.identity(instance)) </ins><span class="cx"> </span><span class="cx"> def identity(self, instance): </span><span class="cx"> """returns the identity (list of primary key values) for the given instance. The list of values can be fed directly into the get() method as mapper.get(*key).""" </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormpropertiespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/properties.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -391,7 +391,7 @@ </span><span class="cx"> for primary_key in self.mapper.pks_by_table[self.mapper.select_table]: </span><span class="cx"> bind = self.lazyreverse[primary_key] </span><span class="cx"> ident.append(params[bind.key]) </span><del>- return self.mapper.using(session).get(*ident) </del><ins>+ return self.mapper.using(session).get(ident) </ins><span class="cx"> elif self.order_by is not False: </span><span class="cx"> order_by = self.order_by </span><span class="cx"> elif self.secondary is not None and self.secondary.default_order_by() is not None: </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormquerypy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/query.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -35,19 +35,19 @@ </span><span class="cx"> props = property(lambda s:s.mapper.props) </span><span class="cx"> session = property(_get_session) </span><span class="cx"> </span><del>- def get(self, *ident, **kwargs): </del><ins>+ def get(self, ident, **kwargs): </ins><span class="cx"> """returns an instance of the object based on the given identifier, or None </span><del>- if not found. The *ident argument is a - list of primary key columns in the order of the table def's primary key columns.""" - key = self.mapper.identity_key(*ident) </del><ins>+ if not found. The ident argument is a scalar or tuple of primary key column values + in the order of the table def's primary key columns.""" + key = self.mapper.identity_key(ident) </ins><span class="cx"> return self._get(key, ident, **kwargs) </span><span class="cx"> </span><del>- def load(self, *ident, **kwargs): </del><ins>+ def load(self, ident, **kwargs): </ins><span class="cx"> """returns an instance of the object based on the given identifier. If not found, </span><span class="cx"> raises an exception. The method will *remove all pending changes* to the object </span><del>- already existing in the Session. The *ident argument is a - list of primary key columns in the order of the table def's primary key columns.""" - key = self.mapper.identity_key(*ident) </del><ins>+ already existing in the Session. The ident argument is a scalar or tuple of primary + key column values in the order of the table def's primary key columns.""" + key = self.mapper.identity_key(ident) </ins><span class="cx"> instance = self._get(key, ident, reload=True, **kwargs) </span><span class="cx"> if instance is None: </span><span class="cx"> raise exceptions.InvalidRequestError("No instance found for identity %s" % repr(ident)) </span><span class="lines">@@ -215,6 +215,8 @@ </span><span class="cx"> </span><span class="cx"> if ident is None: </span><span class="cx"> ident = key[1] </span><ins>+ else: + ident = util.to_list(ident) </ins><span class="cx"> i = 0 </span><span class="cx"> params = {} </span><span class="cx"> for primary_key in self.mapper.pks_by_table[self.table]: </span></span></pre></div> <a id="sqlalchemybranchesschemalibsqlalchemyormsessionpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/lib/sqlalchemy/orm/session.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -227,26 +227,26 @@ </span><span class="cx"> is a list or tuple of objects specifically to be flushed.""" </span><span class="cx"> self.uow.flush(self, objects) </span><span class="cx"> </span><del>- def get(self, class_, *ident, **kwargs): </del><ins>+ def get(self, class_, ident, **kwargs): </ins><span class="cx"> """returns an instance of the object based on the given identifier, or None </span><del>- if not found. The *ident argument is a list of primary key columns in the order of the </del><ins>+ if not found. The ident argument is a scalar or tuple of primary key column values in the order of the </ins><span class="cx"> table def's primary key columns. </span><span class="cx"> </span><span class="cx"> the entity_name keyword argument may also be specified which further qualifies the underlying </span><span class="cx"> Mapper used to perform the query.""" </span><span class="cx"> entity_name = kwargs.get('entity_name', None) </span><del>- return self.query(class_, entity_name=entity_name).get(*ident) </del><ins>+ return self.query(class_, entity_name=entity_name).get(ident) </ins><span class="cx"> </span><del>- def load(self, class_, *ident, **kwargs): </del><ins>+ def load(self, class_, ident, **kwargs): </ins><span class="cx"> """returns an instance of the object based on the given identifier. If not found, </span><span class="cx"> raises an exception. The method will *remove all pending changes* to the object </span><del>- already existing in the Session. The *ident argument is a - list of primary key columns in the order of the table def's primary key columns. </del><ins>+ already existing in the Session. The ident argument is a scalar or tuple of + primary key columns in the order of the table def's primary key columns. </ins><span class="cx"> </span><span class="cx"> the entity_name keyword argument may also be specified which further qualifies the underlying </span><span class="cx"> Mapper used to perform the query.""" </span><span class="cx"> entity_name = kwargs.get('entity_name', None) </span><del>- return self.query(class_, entity_name=entity_name).load(*ident) </del><ins>+ return self.query(class_, entity_name=entity_name).load(ident) </ins><span class="cx"> </span><span class="cx"> def refresh(self, object): </span><span class="cx"> """reloads the attributes for the given object from the database, clears </span><span class="lines">@@ -310,7 +310,7 @@ </span><span class="cx"> for k in ident: </span><span class="cx"> if k is None: </span><span class="cx"> raise InvalidRequestError("Instance '%s' does not have a full set of identity values, and does not represent a saved entity in the database. Use the add() method to add unsaved instances to this Session." % repr(obj)) </span><del>- key = mapper.identity_key(*ident) </del><ins>+ key = mapper.identity_key(ident) </ins><span class="cx"> u = self.uow </span><span class="cx"> if u.identity_map.has_key(key): </span><span class="cx"> # TODO: copy the state of the given object into this one. tricky ! </span></span></pre></div> <a id="sqlalchemybranchesschematestobjectstorepy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/test/objectstore.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/test/objectstore.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/test/objectstore.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -218,7 +218,7 @@ </span><span class="cx"> e.multi_rev = 2 </span><span class="cx"> objectstore.flush() </span><span class="cx"> objectstore.clear() </span><del>- e2 = Entry.mapper.get(e.multi_id, 2) </del><ins>+ e2 = Entry.mapper.get((e.multi_id, 2)) </ins><span class="cx"> self.assert_(e is not e2 and e._instance_key == e2._instance_key) </span><span class="cx"> def testmanualpk(self): </span><span class="cx"> class Entry(object): </span></span></pre></div> <a id="sqlalchemybranchesschematesttablespy"></a> <div class="modfile"><h4>Modified: sqlalchemy/branches/schema/test/tables.py (1369 => 1370)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/branches/schema/test/tables.py 2006-05-01 21:53:27 UTC (rev 1369) +++ sqlalchemy/branches/schema/test/tables.py 2006-05-01 23:07:48 UTC (rev 1370) </span><span class="lines">@@ -56,7 +56,7 @@ </span><span class="cx"> def drop(): </span><span class="cx"> metadata.drop_all() </span><span class="cx"> def delete(): </span><del>- for t in metadata.table_iterator(): </del><ins>+ for t in metadata.table_iterator(reverse=False): </ins><span class="cx"> t.delete().execute() </span><span class="cx"> def user_data(): </span><span class="cx"> users.insert().execute( </span></span></pre> </div> </div> </body> </html> |