[sqlalchemy] Re: set_shard problems

2008-11-28 Thread Ids

Excellent work! Indeed r5335 did fix the problem. Thank you very much
for your help.

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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: set_shard problems

2008-11-27 Thread Ids


Just tested with SQLAlchemy 0.4.8 and that one works fine (see log
below). So something relevant must have changed between 0.4.8 and
0.5.0rc1.

Regards,
Ids

2008-11-27 14:06:51,941 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) _compile_property(id, Column)
2008-11-27 14:06:51,942 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) _compile_property(name, Column)
2008-11-27 14:06:51,947 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) Identified primary key columns: ColumnSet([Column('id',
Integer(), table=persons, primary_key=True, nullable=False)])
2008-11-27 14:06:51,947 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) constructed
2008-11-27 14:06:52,047 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) __initialize_properties() started
2008-11-27 14:06:52,051 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) initialize prop id
2008-11-27 14:06:52,052 INFO sqlalchemy.orm.strategies.ColumnLoader:
register managed attribute id on class Person
2008-11-27 14:06:52,052 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) initialize prop name
2008-11-27 14:06:52,049 INFO sqlalchemy.orm.strategies.ColumnLoader:
register managed attribute name on class Person
2008-11-27 14:06:52,049 INFO sqlalchemy.orm.mapper.Mapper: (Person|
persons) __initialize_properties() complete
2008-11-27 14:06:52,050 DEBUG root: QUERY 1: SELECT persons.id AS
persons_id, persons.name AS persons_name
FROM persons ORDER BY persons.id
 LIMIT 1
2008-11-27 14:06:52,078 INFO sqlalchemy.pool.QueuePool.0x..74: Created
new connection _mysql.connection open to 'localhost' at 829a20c
2008-11-27 14:06:52,078 INFO sqlalchemy.pool.QueuePool.0x..74:
Connection _mysql.connection open to 'localhost' at 829a20c checked
out from pool
2008-11-27 14:06:52,083 INFO sqlalchemy.engine.base.Engine.0x..94:
BEGIN
2008-11-27 14:06:52,084 INFO sqlalchemy.engine.base.Engine.0x..94:
SELECT persons.id AS persons_id, persons.name AS persons_name
FROM persons ORDER BY persons.id
 LIMIT 1
2008-11-27 14:06:52,081 INFO sqlalchemy.engine.base.Engine.0x..94: []
2008-11-27 14:06:52,086 DEBUG sqlalchemy.engine.base.Engine.0x..94:
Col ('persons_id', 'persons_name')
2008-11-27 14:06:52,087 DEBUG sqlalchemy.engine.base.Engine.0x..94:
Row (1L, 'bob')
2008-11-27 14:06:52,091 DEBUG sqlalchemy.orm.mapper.Mapper: (Person|
persons) _instance(): identity key (class '__main__.Person', (1L,),
None) not in session
2008-11-27 14:06:52,092 DEBUG sqlalchemy.orm.mapper.Mapper: (Person|
persons) _instance(): created new instance [EMAIL PROTECTED] identity
(class '__main__.Person', (1L,), None)
2008-11-27 14:06:52,092 DEBUG sqlalchemy.orm.strategies.ColumnLoader:
Returning active column fetcher for Mapper|Person|persons id
2008-11-27 14:06:52,089 DEBUG sqlalchemy.orm.strategies.ColumnLoader:
Returning active column fetcher for Mapper|Person|persons name
2008-11-27 14:06:52,089 DEBUG sqlalchemy.orm.strategies.ColumnLoader:
populating [EMAIL PROTECTED] with RowProxy/id
2008-11-27 14:06:52,090 DEBUG sqlalchemy.orm.strategies.ColumnLoader:
populating [EMAIL PROTECTED] with RowProxy/name
2008-11-27 14:06:52,095 DEBUG root: QUERY 1 RESULT: [__main__.Person
object at 0xb78aa60c]
2008-11-27 14:06:52,095 DEBUG root: QUERY 2: SELECT persons.id AS
persons_id, persons.name AS persons_name
FROM persons
 LIMIT 1

2008-11-27 14:06:52,096 INFO sqlalchemy.engine.base.Engine.0x..94:
SELECT persons.id AS persons_id, persons.name AS persons_name
FROM persons
 LIMIT 1

2008-11-27 14:06:52,094 INFO sqlalchemy.engine.base.Engine.0x..94: {}
2008-11-27 14:06:52,099 DEBUG sqlalchemy.engine.base.Engine.0x..94:
Col ('persons_id', 'persons_name')
2008-11-27 14:06:52,100 DEBUG sqlalchemy.engine.base.Engine.0x..94:
Row (1L, 'bob')
2008-11-27 14:06:52,100 DEBUG root: QUERY 2: RESULT: [(1L, 'bob')]

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



[sqlalchemy] Re: set_shard problems

2008-11-27 Thread Michael Bayer

r5335 will most likely resolve this issue.

On Nov 26, 2008, at 5:21 AM, Ids wrote:


 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
-~--~~~~--~~--~--~---