- attached init2.sql
use a subset of sort tables when we only need to sort on inheritance chains
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)
-
Account Deleted -
Account Deleted - attached test.py
test script (please replace user/password in the DSN)
-
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)
-
Account Deleted - attached test_use_alter.py
this one works
-
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).
-
repo owner - changed status to wontfix
sorry, this test names eight tables that aren't defined here so this is not a useful test case. use_alter is required for cycles in foreign keys, here's the docs which introduce that from an ORM perspective: http://docs.sqlalchemy.org/en/rel_0_7/orm/relationships.html#rows-that-point-to-themselves-mutually-dependent-rows
-
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.
-
repo owner - changed title to use a subset of sort tables when we only need to sort on inheritance chains
- changed milestone to 0.8.0
- removed status
- changed status to open
I see where the use_alter is being required in an unusual place, this can be improved.
-
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()
-
Account Deleted ok.. I'll try to write a more useful test case next time
-
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.
-
repo owner - changed status to resolved
this is 0.8 only since it's destabilizing and is in b297b40fca923a03e3c34094e5298d6524944c39 . sorry for the noise.
-
repo owner - removed milestone
Removing milestone: 0.8.0b1 (automated comment)
- Log in to comment
db script