Hello, I'm experiencing what looks like a bug in SQLAlchemy 0.9.1 through 0.9.8. I use Python 2.7.6. This is the situation:
I have an SQLite database with a many-to-many relationship. This relationship is created using a secondary table, with a left and a right foreign key column. I make use of sqlalchemy.ext.automap to load the table classes for an existing database: engine = sqlalchemy.create_engine('sqlite:///{0}'.format(DB_PATH), echo= True) Session = sessionmaker(bind=engine) session = Session() metadata = sqlalchemy.MetaData() metadata.reflect(bind=engine) Base = automap_base(metadata=metadata) Base.prepare() Photo = Base.classes.photos Taxon = Base.classes.taxa Rank = Base.classes.ranks Because of the many-to-many relationship between Photo and Taxon, I can access the Photo.taxa_collection attribute to get the related taxa for a photo. The problem is that in some cases the collection attributes are not created. For example, if I set the echo attribute for sqlalchemy.create_engine() to False or True (differs per SQLAlchemy version), the script will crash with this error: Traceback (most recent call last): File "./sqla_bug_test_a.py", line 149, in <module> main() File "./sqla_bug_test_a.py", line 126, in main q = get_photos_with_taxa(session, metadata) File "./sqla_bug_test_a.py", line 140, in get_photos_with_taxa join(Photo.taxa_collection).join(Taxon.ranks).\ AttributeError: type object 'photos' has no attribute 'taxa_collection' The collection attributes are not created in this case. The same sometimes happens when I import certain Python modules (e.g. logging or argparse) before sqlalchemy is imported. Sometimes it has to be a combination of these two. I have created a Python script that demonstrates the problem: https://gist.github.com/figure002/2d98ce8532668f9f1bc1 In the comment section below I've included download links to test SQLite databases. In the script I also included some test results for different versions of SQLAlchemy, though the results aren't always consistent. Is this indeed a bug and should I file a bug report? Is there a workaround for this problem? Regards, Serrano -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com. To post to this group, send email to sqlalchemy@googlegroups.com. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.