use a subset of sort tables when we only need to sort on inheritance chains

Issue #2527 resolved
Former user created an issue

Hello,

I'm getting a strange CircularDependencyError with SQLAlchemy 0.7.8, PostgreSQL 9.0.8. I'm using the joined inheritance and the autoload feature.

I've added a test case in attachment

Julien

Comments (13)

  1. Former user Account Deleted

    I digged a little bit more, and it seems that the problem is that ''use_alter=True'' must be set on the foreign keys which have circular dependencies.

    I don't know if this should be considered as a bug in the autoload feature? In other words: Should the autoload feature detects foreign keys which have circular dependencies and automatically set ''use_alter=True'' on those?

    So it works with the following:

        table_content = schema.Table('content', db_meta,
            schema.Column('container_id', types.Integer(),
                      schema.ForeignKey('folder.content_id', use_alter=True,
                                        name='fk_folder')),
    
            schema.Column('icon_content_id', types.Integer(),
                      schema.ForeignKey('data.content_id', use_alter=True,
                                        name='fk_data')),
            autoload=True, 
            extend_existing=True, 
            autoload_replace=True,
            autoload_with = db_engine)
    

    (check test_use_alter.py)

  2. Mike Bayer repo owner

    um ok, here's a tip. I cannot run a test that relies upon reflection, I do not have your database here. If the error is just the use_alter for the FK, no that's not a bug, it's documented.

    I'm going to make the test run and assuming the cirtuclardep is just your FK, this is a "worksforme" (this is why its essential to send along stack traces when issues are first reported).

  3. Mike Bayer repo owner

    I'm just seeing your SQL script, sorry. But in the future I really need succinct test cases that I can run in one step, thanks.

  4. Mike Bayer repo owner

    here is the test case.

    from sqlalchemy import *
    from sqlalchemy.orm import *
    from sqlalchemy.ext.declarative import declarative_base
    
    Base= declarative_base()
    
    class A(Base):
        __tablename__ = "a"
    
        id = Column(Integer, primary_key=True)
        b_id = Column(Integer, ForeignKey('b.id'))
    
    class B(A):
        __tablename__ = "b"
    
        id = Column(Integer, ForeignKey('a.id'), primary_key=True)
    
        __mapper_args__ = {'inherit_condition':id==A.id}
    
    e = create_engine("sqlite://", echo=True)
    
    Base.metadata.create_all(e)
    
    s = Session(e)
    
    s.add(B())
    s.flush()
    
  5. Mike Bayer repo owner

    the reflection is not strictly necessary, however you'd need to know what's going on here to know that, so in this case i can't fault you for that (though you can try removing all those extra tables next time).

    I didn't see the sql scripts since I went straight to the test case in the email, sorry.

  6. Log in to comment