Hello, I think I have found a bug, but I may be doing something wrong. It looks like session.query(<class>).set_shard(<shard_id>) does not work and session.connection(shard_id=<shard_id>).execute does. The first does not return any result, the second one does (even when executing the same query). I've tested it with MySQL 3.23.54 and 5.0.45 and sqlalchemy 0.5.0rc1, rc2 and rc4.
Here is the test database setup: CREATE TABLE persons ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(20) NOT NULL, PRIMARY KEY (id), UNIQUE (name) ); insert into persons (name) values('bob'); insert into persons (name) values('alice'); Here is the test code: #!/opt/python-2.4/bin/python import sys import logging import sqlalchemy as sa from sqlalchemy.orm.shard import ShardedSession from sqlalchemy.orm import sessionmaker from sqlalchemy.ext.declarative import declarative_base logging.basicConfig(stream=sys.stdout, format='%(asctime)s %(levelname) s %(name)s: %(message)s') logging.getLogger('sqlalchemy').setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG) Session = sessionmaker(class_=ShardedSession) Base = declarative_base() class Person(Base): __tablename__ = 'persons' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String(20), unique=True, nullable=False) def __str__(self): return '<Person(%s, %s)>' % (self.id, self.name) def shard_chooser(mapper, instance, clause=None): raise NotImplementedError def id_chooser(query, ident): raise NotImplementedError def query_chooser(query): raise NotImplementedError Session.configure(shard_chooser=shard_chooser, id_chooser=id_chooser, query_chooser=query_chooser) session = Session() shard_id='test' engine = sa.create_engine('mysql://[EMAIL PROTECTED]/%s' % shard_id) session.bind_shard(shard_id, engine) q = session.query(Person).set_shard(shard_id).limit(1) logging.debug("QUERY 1: %s", q) rows = list(q.all()) logging.debug("QUERY 1 RESULT: %s" % rows) # # now to it manually: # q = '''SELECT persons.id AS persons_id, persons.name AS persons_name FROM persons LIMIT 1 ''' logging.debug("QUERY 2: %s", q) rows = session.connection(shard_id=shard_id).execute(q) rows = list(rows) logging.debug("QUERY 2: RESULT: %s" % rows) And here is the code output: 2008-11-26 10:52:26,043 INFO sqlalchemy.orm.strategies.ColumnLoader: Person.id register managed attribute 2008-11-26 10:52:26,044 INFO sqlalchemy.orm.strategies.ColumnLoader: Person.name register managed attribute 2008-11-26 10:52:26,045 DEBUG root: QUERY 1: SELECT persons.id AS persons_id, persons.name AS persons_name FROM persons LIMIT 1 2008-11-26 10:52:26,061 INFO sqlalchemy.pool.QueuePool.0x...8bf4: Created new connection <_mysql.connection open to 'localhost' at 82b02ec> 2008-11-26 10:52:26,062 INFO sqlalchemy.pool.QueuePool.0x...8bf4: Connection <_mysql.connection open to 'localhost' at 82b02ec> checked out from pool 2008-11-26 10:52:26,062 INFO sqlalchemy.engine.base.Engine.0x...8a14: BEGIN 2008-11-26 10:52:26,060 INFO sqlalchemy.engine.base.Engine.0x...8a14: SELECT persons.id AS persons_id, persons.name AS persons_name FROM persons LIMIT 1 2008-11-26 10:52:26,064 INFO sqlalchemy.engine.base.Engine.0x...8a14: [] 2008-11-26 10:52:26,066 DEBUG sqlalchemy.engine.base.Engine.0x...8a14: Col ('persons_id', 'persons_name') 2008-11-26 10:52:26,070 DEBUG root: QUERY 1 RESULT: [] 2008-11-26 10:52:26,070 DEBUG root: QUERY 2: SELECT persons.id AS persons_id, persons.name AS persons_name FROM persons LIMIT 1 2008-11-26 10:52:26,071 INFO sqlalchemy.engine.base.Engine.0x...8a14: SELECT persons.id AS persons_id, persons.name AS persons_name FROM persons LIMIT 1 2008-11-26 10:52:26,071 INFO sqlalchemy.engine.base.Engine.0x...8a14: {} 2008-11-26 10:52:26,073 DEBUG sqlalchemy.engine.base.Engine.0x...8a14: Col ('persons_id', 'persons_name') 2008-11-26 10:52:26,073 DEBUG sqlalchemy.engine.base.Engine.0x...8a14: Row (1L, 'bob') 2008-11-26 10:52:26,074 DEBUG root: QUERY 2: RESULT: [(1L, 'bob')] There are two things I notice in the sqlalchemy.Engine logs; the second SELECT statement seems to have an additional newline and the next log (which seem to be the parameters for the select statement) contain a {} instead of a []. Am I doing something wrong here or is this supposed to work? Regards, Ids --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---