On May 17, 2012, at 6:18 PM, Demitri Muna wrote:

> 
>> A bug report for SQLA would look like this:
>> 
>> t1 = Table("table1", metadata, schema="schema1", autoload=True, 
>> autoload_with=some_engine)
>> t2 = Table("table2", metadata, schema="schema2", autoload=True, 
>> autoload_with=some_engine)
>> 
>> assert t1.c.some_column.references(t2.c.some_other_column)
>> 
>> that is, "some_column" is expected to have a ForeignKey to 
>> "some_other_column" based on the reflection.
>> 
>> Please provide that including the raw "CREATE TABLE" statements, removing 
>> any extraneous columns and data not needed to reproduce the issue.
> 
> See attached. I've created a very simple toy model to demonstrate this. The 
> full database I created is provided as an SQL dump. I'm using PostgreSQL 
> 9.0.5. No data is required to make the assertions I made fail. The code 
> provided is in three Python files - one that defines the database connection, 
> another that defines the model classes (both designed for use by many 
> scripts), and a third script that is the one that should be executed. The 
> database user is "schema_test". The code of interest appears in lines 37-57 
> of ModelClasses.py. Finally, you'll have to update the database connection 
> information for your setup at the top of "multiple_schema_test.py".

OK this is way too much verbiage.  If the error is as you describe, a bug 
involving reflection of two tables across two schemas, I'd need a test which 
illustrates this alone, no ORM or full database dumps, with a simple failure to 
identify a foreign key constraint between them.   I've attached a sample of 
exactly what I'd like to see.

If the issue is not as simple as this, then we will have to dig into multiple 
tables, mappings, etc. but you should be able to reproduce the specific case 
here with just two tables.



from sqlalchemy import *

"""
CREATE TABLE test_schema.table_a (id INTEGER primary key);
CREATE TABLE test_schema_2.table_b (id INTEGER primary key, ta_id INTEGER REFERENCES test_schema.table_a(id));

"""

e = create_engine("postgresql://scott:tiger@localhost/test", echo=True)

m = MetaData()
t1 = Table("table_a", schema="test_schema", autoload=True, autoload_with=e)
t2 = Table("table_b", schema="test_schema_2", autoload=True, autoload_with=e)

assert t2.c.ta_id.references(t1.c.id)
-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to