[Sqlalchemy-commits] [5203] sqlalchemy/trunk: Fixed mysql FK reflection for the edge case where a T
Brought to you by:
zzzeek
<!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><meta http-equiv="content-type" content="text/html; charset=utf-8" /><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, #header, #footer { 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; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #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>[5203] sqlalchemy/trunk: Fixed mysql FK reflection for the edge case where a Table has expicitly provided a schema = that matches the connection's default schema.</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>5203</dd> <dt>Author</dt> <dd>jek</dd> <dt>Date</dt> <dd>2008-10-27 18:56:53 -0400 (Mon, 27 Oct 2008)</dd> </dl> <h3>Log Message</h3> <pre>Fixed mysql FK reflection for the edge case where a Table has expicitly provided a schema= that matches the connection's default schema.</pre> <h3>Modified Paths</h3> <ul> <li><a href="#sqlalchemytrunkCHANGES">sqlalchemy/trunk/CHANGES</a></li> <li><a href="#sqlalchemytrunklibsqlalchemydatabasesmysqlpy">sqlalchemy/trunk/lib/sqlalchemy/databases/mysql.py</a></li> <li><a href="#sqlalchemytrunktestenginereflectionpy">sqlalchemy/trunk/test/engine/reflection.py</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="sqlalchemytrunkCHANGES"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/CHANGES (5202 => 5203)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/CHANGES 2008-10-27 19:49:49 UTC (rev 5202) +++ sqlalchemy/trunk/CHANGES 2008-10-27 22:56:53 UTC (rev 5203) </span><span class="lines">@@ -7,75 +7,76 @@ </span><span class="cx"> 0.5.0rc3 </span><span class="cx"> ======== </span><span class="cx"> - orm </span><del>- - "not equals" comparisons of simple many-to-one relation - to an instance will not drop into an EXISTS clause - and will compare foreign key columns instead. - - - removed not-really-working use cases of comparing - a collection to an iterable. Use contains() to test - for collection membership. </del><ins>+ - "not equals" comparisons of simple many-to-one relation to an + instance will not drop into an EXISTS clause and will compare + foreign key columns instead. </ins><span class="cx"> </span><del>- - Improved weakref identity map memory management to no longer - require mutexing, resurrects garbage collected instance - on a lazy basis for an InstanceState with pending changes. </del><ins>+ - Removed not-really-working use cases of comparing a collection + to an iterable. Use contains() to test for collection + membership. </ins><span class="cx"> </span><ins>+ - Improved weakref identity map memory management to no longer + require mutexing, resurrects garbage collected instance on a + lazy basis for an InstanceState with pending changes. + </ins><span class="cx"> - relation() won't hide unrelated ForeignKey errors inside of </span><del>- the "please specify primaryjoin" message when determining - join condition. - - - When using Query.join() with an explicit clause for the - ON clause, the clause will be aliased in terms of the left - side of the join, allowing scenarios like query(Source). </del><ins>+ the "please specify primaryjoin" message when determining join + condition. + + - When using Query.join() with an explicit clause for the ON + clause, the clause will be aliased in terms of the left side + of the join, allowing scenarios like query(Source). </ins><span class="cx"> from_self().join((Dest, Source.id==Dest.source_id)) to work </span><span class="cx"> properly. </span><del>- - - polymorphic_union() function respects the "key" of each - Column if they differ from the column's name. </del><span class="cx"> </span><del>- - Added more granularity to internal attribute access, such - that cascade and flush operations will not initialize - unloaded attributes and collections, leaving them intact for - a lazy-load later on. Backref events still initialize - attrbutes and collections for pending instances. - [ticket:1202] - - - InstanceState object now removes circular references to - itself upon disposal to keep it outside of cyclic garbage - collection. - </del><ins>+ - polymorphic_union() function respects the "key" of each Column + if they differ from the column's name. + + - Added more granularity to internal attribute access, such that + cascade and flush operations will not initialize unloaded + attributes and collections, leaving them intact for a + lazy-load later on. Backref events still initialize attrbutes + and collections for pending instances. [ticket:1202] + + - InstanceState object now removes circular references to itself + upon disposal to keep it outside of cyclic garbage collection. + </ins><span class="cx"> - sql </span><del>- - Further simplified SELECT compilation and its relationship - to result row processing. </del><ins>+ - Further simplified SELECT compilation and its relationship to + result row processing. </ins><span class="cx"> </span><span class="cx"> - Direct execution of a union() construct will properly set up </span><span class="cx"> result-row processing. [ticket:1194] </span><span class="cx"> </span><span class="cx"> - The internal notion of an "OID" or "ROWID" column has been </span><span class="cx"> removed. It's basically not used by any dialect, and the </span><del>- possibility of its usage with psycopg2's cursor.lastrowid - is basically gone now that INSERT..RETURNING is available. - - - Removed "default_order_by()" method on all FromClause - objects. </del><ins>+ possibility of its usage with psycopg2's cursor.lastrowid is + basically gone now that INSERT..RETURNING is available. </ins><span class="cx"> </span><ins>+ - Removed "default_order_by()" method on all FromClause objects. + </ins><span class="cx"> - Slightly changed behavior of IN operator for comparing to </span><span class="cx"> empty collections. Now results in inequality comparison </span><del>- against self. More portable, but breaks with stored - procedures that aren't pure functions. </del><ins>+ against self. More portable, but breaks with stored procedures + that aren't pure functions. </ins><span class="cx"> </span><span class="cx"> - oracle </span><span class="cx"> - Removed FIRST_ROWS() optimize flag when using LIMIT/OFFSET, </span><span class="cx"> can be reenabled with optimize_limits=True create_engine() </span><span class="cx"> flag. [ticket:536] </span><span class="cx"> </span><del>- - Wrote a docstring for Oracle dialect. Apparently that - Ohloh "few source code comments" label is starting to sting - :). </del><ins>+ - Wrote a docstring for Oracle dialect. Apparently that Ohloh + "few source code comments" label is starting to sting :). </ins><span class="cx"> </span><del>- - Setting the auto_convert_lobs to False on create_engine() - will also instruct the OracleBinary type to return the - cx_oracle LOB object unchanged. </del><ins>+ - Setting the auto_convert_lobs to False on create_engine() will + also instruct the OracleBinary type to return the cx_oracle + LOB object unchanged. </ins><span class="cx"> </span><ins>+- mysql + - Fixed foreign key reflection in the edge case where a Table's + explicit schema= is the same as the schema (database) the + connection is attached to. + </ins><span class="cx"> 0.5.0rc2 </span><span class="cx"> ======== </span><span class="cx"> - orm </span></span></pre></div> <a id="sqlalchemytrunklibsqlalchemydatabasesmysqlpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/lib/sqlalchemy/databases/mysql.py (5202 => 5203)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/lib/sqlalchemy/databases/mysql.py 2008-10-27 19:49:49 UTC (rev 5202) +++ sqlalchemy/trunk/lib/sqlalchemy/databases/mysql.py 2008-10-27 22:56:53 UTC (rev 5203) </span><span class="lines">@@ -2334,11 +2334,20 @@ </span><span class="cx"> def _set_constraints(self, table, constraints, connection, only): </span><span class="cx"> """Apply constraints to a ``Table``.""" </span><span class="cx"> </span><ins>+ default_schema = None + </ins><span class="cx"> for spec in constraints: </span><span class="cx"> # only FOREIGN KEYs </span><span class="cx"> ref_name = spec['table'][-1] </span><span class="cx"> ref_schema = len(spec['table']) > 1 and spec['table'][-2] or None </span><span class="cx"> </span><ins>+ if not ref_schema: + if default_schema is None: + default_schema = connection.dialect.get_default_schema_name( + connection) + if table.schema == default_schema: + ref_schema = table.schema + </ins><span class="cx"> loc_names = spec['local'] </span><span class="cx"> if only and not set(loc_names).issubset(only): </span><span class="cx"> self.logger.info( </span></span></pre></div> <a id="sqlalchemytrunktestenginereflectionpy"></a> <div class="modfile"><h4>Modified: sqlalchemy/trunk/test/engine/reflection.py (5202 => 5203)</h4> <pre class="diff"><span> <span class="info">--- sqlalchemy/trunk/test/engine/reflection.py 2008-10-27 19:49:49 UTC (rev 5202) +++ sqlalchemy/trunk/test/engine/reflection.py 2008-10-27 22:56:53 UTC (rev 5203) </span><span class="lines">@@ -696,19 +696,23 @@ </span><span class="cx"> metadata = MetaData(engine) </span><span class="cx"> table1 = Table('table1', metadata, </span><span class="cx"> Column('col1', sa.Integer, primary_key=True), </span><ins>+ test_needs_fk=True, </ins><span class="cx"> schema=schema) </span><span class="cx"> table2 = Table('table2', metadata, </span><span class="cx"> Column('col1', sa.Integer, primary_key=True), </span><span class="cx"> Column('col2', sa.Integer, </span><span class="cx"> sa.ForeignKey('%s.table1.col1' % schema)), </span><ins>+ test_needs_fk=True, </ins><span class="cx"> schema=schema) </span><span class="cx"> try: </span><span class="cx"> metadata.create_all() </span><span class="cx"> metadata.create_all(checkfirst=True) </span><ins>+ assert len(metadata.tables) == 2 </ins><span class="cx"> metadata.clear() </span><span class="cx"> </span><span class="cx"> table1 = Table('table1', metadata, autoload=True, schema=schema) </span><span class="cx"> table2 = Table('table2', metadata, autoload=True, schema=schema) </span><ins>+ assert len(metadata.tables) == 2 </ins><span class="cx"> finally: </span><span class="cx"> metadata.drop_all() </span><span class="cx"> </span></span></pre> </div> </div> </body> </html> |