The following short script behaves differently if run with no arguments or with arguments:
from elixir import * import os from sqlalchemy import Unicode, select, and_, __version__ import sys class School(Entity): name = Field(Unicode(50), required=True) class Subject(Entity): name = Field(Unicode(50), required=True) teachers = ManyToMany('Teacher', local_colname='course_id', remote_colname='prof_id') school = ManyToOne('School') class Teacher(Entity): name = Field(Unicode(50), required=True) def main(): if os.path.exists('/tmp/schools.db'): os.remove('/tmp/schools.db') metadata.bind = "sqlite:////tmp/schools.db" setup_all(create_tables=True) school = School(name='Rydell High') session.commit() r = Subject._descriptor.find_relationship('teachers') t = r.table if len(sys.argv) > 1: c = Subject.school == school else: c = Subject.school_id == school.id s = select([Teacher.name], and_(c, t.c.prof_id == Teacher.id, t.c.course_id == Subject.id)) metadata.bind.echo = True print('Executing query using SQLAlchemy', __version__) session.execute(s) if __name__ == '__main__': main() The script chooses between two comparator conditions: Subject.school == school or Subject.school_id == school.id before running a SQLA select query using the chosen comparator. In one case the generated SQL is printed, and in the other it's not, despite echo being set to True. In the real program of which this is a cut-down example, the query ran correctly in either case, so it's just the engine.echo behaviour which is odd. Sorry this is an Elixir script - I'm unable to reproduce using just SQLAlchemy, but it seems unlikely to be an Elixir issue. It seems to be a subtle enough bug (if bug it is) that removing Elixir from the picture causes the bug to disappear from view. Why should the two cases behave differently? Regards, Vinay Sajip -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.