[sqlalchemy] [0.7.1] Building C extentions fail on installing for OS X

2011-06-24 Thread Martijn
When installing on OSX the install log shows:

building 'sqlalchemy.cprocessors' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall 
-Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 -pipe 
-I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c 
lib/sqlalchemy/cextension/processors.c -o 
build/temp.macosx-10.6-universal-2.6/lib/sqlalchemy/cextension/processors.o
/usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler 
(/usr/bin/../libexec/gcc/darwin/ppc/as or 
/usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not installed
Installed assemblers are:
/usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
/usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
***
command 'gcc-4.2' failed with exit status 1
WARNING: The C extension could not be compiled, speedups are not enabled.
Failure information, if any, is above.
Retrying the build without the C extension now.
***



I am not much of a C guru but I think I do need to remove -arch ppc from the 
gcc options

I am up to date with both OS X and Xcode and it seems universal binary 
related...

I have searched the list but could not find anything related

Martijn

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



Re: [sqlalchemy] [0.7.1] Building C extentions fail on installing for OS X

2011-06-24 Thread Tony Theodore
On 24 June 2011 18:50, Martijn mart...@xs4us.nu wrote:
 When installing on OSX the install log shows:

 building 'sqlalchemy.cprocessors' extension
 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os 
 -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 
 -pipe 
 -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 
 -c lib/sqlalchemy/cextension/processors.c -o 
 build/temp.macosx-10.6-universal-2.6/lib/sqlalchemy/cextension/processors.o
 /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler 
 (/usr/bin/../libexec/gcc/darwin/ppc/as or 
 /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not 
 installed
 Installed assemblers are:
 /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
 /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
 ***
 command 'gcc-4.2' failed with exit status 1
 WARNING: The C extension could not be compiled, speedups are not enabled.
 Failure information, if any, is above.
 Retrying the build without the C extension now.
 ***



 I am not much of a C guru but I think I do need to remove -arch ppc from 
 the gcc options

 I am up to date with both OS X and Xcode and it seems universal binary 
 related...

 I have searched the list but could not find anything related

I don't know too much about C extensions either, but you seem to be
using the Apple supplied version of Python. Try using either the
python.org or macports versions - you'll generally have less problems
with those.

Cheers,

Tony

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



Re: [sqlalchemy] [0.7.1] Building C extentions fail on installing for OS X

2011-06-24 Thread Martijn
Thanks, but changing is not a real option for now since lots of modules are 
compiled against this version
I never had this problem with other versions of sqla though

It is about time PPC supported by default should be dropped..

 
On Jun 24, 2011, at 12:30 , Tony Theodore wrote:

 On 24 June 2011 18:50, Martijn mart...@xs4us.nu wrote:
 When installing on OSX the install log shows:
 
 building 'sqlalchemy.cprocessors' extension
 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os 
 -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 
 -pipe 
 -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 
 -c lib/sqlalchemy/cextension/processors.c -o 
 build/temp.macosx-10.6-universal-2.6/lib/sqlalchemy/cextension/processors.o
 /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler 
 (/usr/bin/../libexec/gcc/darwin/ppc/as or 
 /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not 
 installed
 Installed assemblers are:
 /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
 /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
 ***
 command 'gcc-4.2' failed with exit status 1
 WARNING: The C extension could not be compiled, speedups are not enabled.
 Failure information, if any, is above.
 Retrying the build without the C extension now.
 ***
 
 
 
 I am not much of a C guru but I think I do need to remove -arch ppc from 
 the gcc options
 
 I am up to date with both OS X and Xcode and it seems universal binary 
 related...
 
 I have searched the list but could not find anything related
 
 I don't know too much about C extensions either, but you seem to be
 using the Apple supplied version of Python. Try using either the
 python.org or macports versions - you'll generally have less problems
 with those.
 
 Cheers,
 
 Tony
 
 -- 
 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.
 

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



Re: [sqlalchemy] [0.7.1] Building C extentions fail on installing for OS X

2011-06-24 Thread Michael Bayer


This is a distutils issue, those flags are part of your Python install.
There's ways to affect what they come out as with environment variables, but in 
my experience installing the OSX build from the Python site (or building a new 
Python from scrtch) is usually the only way to really get native C extensions 
to build - the system python is glitchy.

Of course if you're just on your workstation, the C extensions are not of 
critical importance in any case.


On Jun 24, 2011, at 10:38 AM, Martijn wrote:

 Thanks, but changing is not a real option for now since lots of modules are 
 compiled against this version
 I never had this problem with other versions of sqla though
 
 It is about time PPC supported by default should be dropped..
 
 
 On Jun 24, 2011, at 12:30 , Tony Theodore wrote:
 
 On 24 June 2011 18:50, Martijn mart...@xs4us.nu wrote:
 When installing on OSX the install log shows:
 
 building 'sqlalchemy.cprocessors' extension
 gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os 
 -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch ppc -arch x86_64 
 -pipe 
 -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6
  -c lib/sqlalchemy/cextension/processors.c -o 
 build/temp.macosx-10.6-universal-2.6/lib/sqlalchemy/cextension/processors.o
 /usr/libexec/gcc/powerpc-apple-darwin10/4.2.1/as: assembler 
 (/usr/bin/../libexec/gcc/darwin/ppc/as or 
 /usr/bin/../local/libexec/gcc/darwin/ppc/as) for architecture ppc not 
 installed
 Installed assemblers are:
 /usr/bin/../libexec/gcc/darwin/x86_64/as for architecture x86_64
 /usr/bin/../libexec/gcc/darwin/i386/as for architecture i386
 ***
 command 'gcc-4.2' failed with exit status 1
 WARNING: The C extension could not be compiled, speedups are not enabled.
 Failure information, if any, is above.
 Retrying the build without the C extension now.
 ***
 
 
 
 I am not much of a C guru but I think I do need to remove -arch ppc from 
 the gcc options
 
 I am up to date with both OS X and Xcode and it seems universal binary 
 related...
 
 I have searched the list but could not find anything related
 
 I don't know too much about C extensions either, but you seem to be
 using the Apple supplied version of Python. Try using either the
 python.org or macports versions - you'll generally have less problems
 with those.
 
 Cheers,
 
 Tony
 
 -- 
 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.
 
 
 -- 
 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.
 

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



[sqlalchemy] per-host pooling vs per-engine pooling

2011-06-24 Thread Tarek Ziadé
Hello

I was wondering if there's a simple way to do per-host pooling.

Here's my use case: I have several hosts and on each one of them has
several databases hosted in mysql.

the engine is tied to a specific database when you create it, so the
default pool will pool connection on a specific database.

what I'd like to do is share the same pool of connectors across all
engines that are working with a given host.f

Example in pseudo-code:

pool_server1 = Pool('mysql://server1', size=10)

engine1 = create_engine('mysql://server1/database1', pool=pool_server1)
engine2 = create_engine('mysql://server1/database2', pool=pool_server1)

The goal is to reduce the number of sockets open for every host

Is there a way to do it with the existing pools ?   If not, I guess
I'll work on a custom Pool,

Thanks
Tarek
-- 
Tarek Ziadé | http://ziade.org

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



[sqlalchemy] Error using Versioned objects and Association Proxy together

2011-06-24 Thread 371c
Hi all,

I have a problem when using the versioned recipe together with
Association proxy. Some code may make this clear:

import...

class ItemKeywordAsso(Base):

__tablename__ = item_keywords

 id = Column(Integer, primary_key=True)
item_id = Column(Integer, ForeignKey('items.id'), index=True)
keyword_id = Column(Integer, ForeignKey('keywords.id'), index=True)

item = relationship(Item, backref=item_keywords)
keyword = relationship(Keyword, lazy=joined)

def __init__(self, item=None, keyword=None):
self.item = item
self.keyword = keyword

class Item(Base, InnodbTableMixin):

__metaclass__ = VersionedMeta
__tablename__ = 'items'

id = Column(Integer, primary_key=True)
name = Column(Unicode(255))
description = Column(UnicodeText)

keywords = association_proxy(item_keywords, keyword,
 creator=lambda k: \
 ItemKeywordAsso(keyword=k))


The Error produced:

ERROR: Failure: InvalidRequestError (Table 'item_keywords' is already
defined for this MetaData instance.  Specify 'extend_existing=True' to
redefine options and columns on an existing Table object.)

However: If i remove the __metaclass__= VersionedMeta in the Item
class, everything works normally.

Has anyone come across this? Any suggestions?

Regards,
Eric.

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



[sqlalchemy] query_chooser and relationship queries

2011-06-24 Thread Arthur Kopatsy
Hi,

I am trying to write a proper query_chooser method for our user based
sharding. To do so, I need to be able to query the value of the
query's criterions.

I have the following model:
class User(object):
id = Column(Integer, primary_key=True)
...

class Subscription(object):
id = Column(Integer, primary_key=True)
producerId = Column(Integer, ForeignKey('User.id'))
consumerId = Column(Integer) # No foreign key because sharded on
producerId
producer = relationship('User', backref='subscriptions')

In my query_chooser, I am using the code from the attribute_sharding
example and try to find out the value of producerId if there is such a
criterion.

Given an existing myUser instance and a session, I see two different
behaviors:

1. session.query(Subscription).filter(Subscription.producerId ==
myUser.id).all()

I will get a proper value for producerId in the dictionary of bound
parameters so I can find out the shard, no problem.

SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
InboundSubscription.active AS InboundSubscription_active,
InboundSubscription.createdAt AS InboundSubscription_createdAt,
InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
InboundSubscription.followerId AS
InboundSubscription_followerId, InboundSubscription.producerId
AS InboundSubscription_producerId, InboundSubscription.status AS
InboundSubscription_status, InboundSubscription.suspended AS
InboundSubscription_suspended
FROM InboundSubscription
WHERE InboundSubscription.producerId = :producerId_1

2. myUser.subscriptions

I get a None value for the anonymous parameter which prevents me from
picking a shard.

SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
InboundSubscription.active AS InboundSubscription_active,
InboundSubscription.createdAt AS InboundSubscription_createdAt,
InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
InboundSubscription.followerId AS
InboundSubscription_followerId, InboundSubscription.producerId
AS InboundSubscription_producerId, InboundSubscription.status AS
InboundSubscription_status, InboundSubscription.suspended AS
InboundSubscription_suspended
FROM InboundSubscription
WHERE :param_1 = InboundSubscription.producerId

When is this value populated? How can I access it in query_chooser?

Thanks in advance for you help. I am using sqlalchemy 0.7.1

Arthur

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



Re: [sqlalchemy] per-host pooling vs per-engine pooling

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 11:01 AM, Tarek Ziadé wrote:

 Hello
 
 I was wondering if there's a simple way to do per-host pooling.
 
 Here's my use case: I have several hosts and on each one of them has
 several databases hosted in mysql.
 
 the engine is tied to a specific database when you create it, so the
 default pool will pool connection on a specific database.
 
 what I'd like to do is share the same pool of connectors across all
 engines that are working with a given host.f
 
 Example in pseudo-code:
 
 pool_server1 = Pool('mysql://server1', size=10)
 
 engine1 = create_engine('mysql://server1/database1', pool=pool_server1)
 engine2 = create_engine('mysql://server1/database2', pool=pool_server1)
 
 The goal is to reduce the number of sockets open for every host
 
 Is there a way to do it with the existing pools ?   If not, I guess
 I'll work on a custom Pool,

well a pool is geared towards one specific connection which already has a 
database set up on it.I guess maybe you'd use pool events to switch the 
database on checkout.

You can share a pool between engines using the pool argument to 
create_engine(), but one problem with that right now is that the dialect which 
is per-engine uses the on first checkout event to handle some important 
dialect initialization.  That step would have to be accommodated in some way.

Also this solution is only local to one Python process, not even a fork.  You 
might have a simpler time limiting TCP connections using a product like 
PGBouncer, and turn pooling way down or off for each SQLAlchemy pool, that way 
you can truly limit connections per host.


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



Re: [sqlalchemy] query_chooser and relationship queries

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 12:49 PM, Arthur Kopatsy wrote:

 Hi,
 
 I am trying to write a proper query_chooser method for our user based
 sharding. To do so, I need to be able to query the value of the
 query's criterions.
 
 I have the following model:
 class User(object):
id = Column(Integer, primary_key=True)
...
 
 class Subscription(object):
id = Column(Integer, primary_key=True)
producerId = Column(Integer, ForeignKey('User.id'))
consumerId = Column(Integer) # No foreign key because sharded on
 producerId
producer = relationship('User', backref='subscriptions')
 
 In my query_chooser, I am using the code from the attribute_sharding
 example and try to find out the value of producerId if there is such a
 criterion.
 
 Given an existing myUser instance and a session, I see two different
 behaviors:
 
 1. session.query(Subscription).filter(Subscription.producerId ==
 myUser.id).all()
 
 I will get a proper value for producerId in the dictionary of bound
 parameters so I can find out the shard, no problem.
 
 SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
 InboundSubscription.active AS InboundSubscription_active,
 InboundSubscription.createdAt AS InboundSubscription_createdAt,
 InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
 InboundSubscription.followerId AS
 InboundSubscription_followerId, InboundSubscription.producerId
 AS InboundSubscription_producerId, InboundSubscription.status AS
 InboundSubscription_status, InboundSubscription.suspended AS
 InboundSubscription_suspended
 FROM InboundSubscription
 WHERE InboundSubscription.producerId = :producerId_1
 
 2. myUser.subscriptions
 
 I get a None value for the anonymous parameter which prevents me from
 picking a shard.
 
 SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
 InboundSubscription.active AS InboundSubscription_active,
 InboundSubscription.createdAt AS InboundSubscription_createdAt,
 InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
 InboundSubscription.followerId AS
 InboundSubscription_followerId, InboundSubscription.producerId
 AS InboundSubscription_producerId, InboundSubscription.status AS
 InboundSubscription_status, InboundSubscription.suspended AS
 InboundSubscription_suspended
 FROM InboundSubscription
 WHERE :param_1 = InboundSubscription.producerId
 
 When is this value populated? How can I access it in query_chooser?


The bindparam() object should have a callable attribute - call that to get 
the value.These values are late-bound when using lazyloading.

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



Re: [sqlalchemy] Error using Versioned objects and Association Proxy together

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 12:03 PM, 371c wrote:

 Hi all,
 
 I have a problem when using the versioned recipe together with
 Association proxy. Some code may make this clear:
 
 import...
 
 class ItemKeywordAsso(Base):
 
   __tablename__ = item_keywords
 
id = Column(Integer, primary_key=True)
   item_id = Column(Integer, ForeignKey('items.id'), index=True)
   keyword_id = Column(Integer, ForeignKey('keywords.id'), index=True)
 
   item = relationship(Item, backref=item_keywords)
   keyword = relationship(Keyword, lazy=joined)
 
   def __init__(self, item=None, keyword=None):
   self.item = item
   self.keyword = keyword
 
 class Item(Base, InnodbTableMixin):
 
__metaclass__ = VersionedMeta
__tablename__ = 'items'
 
   id = Column(Integer, primary_key=True)
   name = Column(Unicode(255))
   description = Column(UnicodeText)
 
   keywords = association_proxy(item_keywords, keyword,
 creator=lambda k: \
 ItemKeywordAsso(keyword=k))
 
 
 The Error produced:
 
 ERROR: Failure: InvalidRequestError (Table 'item_keywords' is already
 defined for this MetaData instance.  Specify 'extend_existing=True' to
 redefine options and columns on an existing Table object.)
 
 However: If i remove the __metaclass__= VersionedMeta in the Item
 class, everything works normally.
 
 Has anyone come across this? Any suggestions?

i doubt that has anything to do with the association proxy, and it appears like 
the example is inadvertently creating an item_keywords table a second time.  
can you provide a full example case ?


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



[sqlalchemy] Re: query_chooser and relationship queries

2011-06-24 Thread Arthur Kopatsy
Awesome.

Does that mean the sqlalchemy example is wrong. It currently has:
if callable(value):
value = value()

Should it be something like that?

if value == None and bind.callable !=
None:
|verificationTokenExpiry = Column(String)
value = bind.callable()

Thank you so much for the quick response.

Arthur


On Jun 24, 10:05 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 24, 2011, at 12:49 PM, Arthur Kopatsy wrote:









  Hi,

  I am trying to write a proper query_chooser method for our user based
  sharding. To do so, I need to be able to query the value of the
  query's criterions.

  I have the following model:
  class User(object):
     id = Column(Integer, primary_key=True)
     ...

  class Subscription(object):
     id = Column(Integer, primary_key=True)
     producerId = Column(Integer, ForeignKey('User.id'))
     consumerId = Column(Integer) # No foreign key because sharded on
  producerId
     producer = relationship('User', backref='subscriptions')

  In my query_chooser, I am using the code from the attribute_sharding
  example and try to find out the value of producerId if there is such a
  criterion.

  Given an existing myUser instance and a session, I see two different
  behaviors:

  1. session.query(Subscription).filter(Subscription.producerId ==
  myUser.id).all()

  I will get a proper value for producerId in the dictionary of bound
  parameters so I can find out the shard, no problem.

  SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
  InboundSubscription.active AS InboundSubscription_active,
  InboundSubscription.createdAt AS InboundSubscription_createdAt,
  InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
  InboundSubscription.followerId AS
  InboundSubscription_followerId, InboundSubscription.producerId
  AS InboundSubscription_producerId, InboundSubscription.status AS
  InboundSubscription_status, InboundSubscription.suspended AS
  InboundSubscription_suspended
  FROM InboundSubscription
  WHERE InboundSubscription.producerId = :producerId_1

  2. myUser.subscriptions

  I get a None value for the anonymous parameter which prevents me from
  picking a shard.

  SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
  InboundSubscription.active AS InboundSubscription_active,
  InboundSubscription.createdAt AS InboundSubscription_createdAt,
  InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
  InboundSubscription.followerId AS
  InboundSubscription_followerId, InboundSubscription.producerId
  AS InboundSubscription_producerId, InboundSubscription.status AS
  InboundSubscription_status, InboundSubscription.suspended AS
  InboundSubscription_suspended
  FROM InboundSubscription
  WHERE :param_1 = InboundSubscription.producerId

  When is this value populated? How can I access it in query_chooser?

 The bindparam() object should have a callable attribute - call that to get 
 the value.    These values are late-bound when using lazyloading.

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



Re: [sqlalchemy] Re: query_chooser and relationship queries

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 1:26 PM, Arthur Kopatsy wrote:

 Awesome.
 
 Does that mean the sqlalchemy example is wrong. It currently has:
if callable(value):
value = value()
 

yeah thats out of date, usage  was changed in 0.7.


 Should it be something like that?
 
if value == None and bind.callable !=
 None:
 |verificationTokenExpiry = Column(String)
value = bind.callable()
 
 Thank you so much for the quick response.

yupwe had the same issue with beaker ill have to update this example


 
 Arthur
 
 
 On Jun 24, 10:05 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 24, 2011, at 12:49 PM, Arthur Kopatsy wrote:
 
 
 
 
 
 
 
 
 
 Hi,
 
 I am trying to write a proper query_chooser method for our user based
 sharding. To do so, I need to be able to query the value of the
 query's criterions.
 
 I have the following model:
 class User(object):
id = Column(Integer, primary_key=True)
...
 
 class Subscription(object):
id = Column(Integer, primary_key=True)
producerId = Column(Integer, ForeignKey('User.id'))
consumerId = Column(Integer) # No foreign key because sharded on
 producerId
producer = relationship('User', backref='subscriptions')
 
 In my query_chooser, I am using the code from the attribute_sharding
 example and try to find out the value of producerId if there is such a
 criterion.
 
 Given an existing myUser instance and a session, I see two different
 behaviors:
 
 1. session.query(Subscription).filter(Subscription.producerId ==
 myUser.id).all()
 
 I will get a proper value for producerId in the dictionary of bound
 parameters so I can find out the shard, no problem.
 
 SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
 InboundSubscription.active AS InboundSubscription_active,
 InboundSubscription.createdAt AS InboundSubscription_createdAt,
 InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
 InboundSubscription.followerId AS
 InboundSubscription_followerId, InboundSubscription.producerId
 AS InboundSubscription_producerId, InboundSubscription.status AS
 InboundSubscription_status, InboundSubscription.suspended AS
 InboundSubscription_suspended
 FROM InboundSubscription
 WHERE InboundSubscription.producerId = :producerId_1
 
 2. myUser.subscriptions
 
 I get a None value for the anonymous parameter which prevents me from
 picking a shard.
 
 SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
 InboundSubscription.active AS InboundSubscription_active,
 InboundSubscription.createdAt AS InboundSubscription_createdAt,
 InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
 InboundSubscription.followerId AS
 InboundSubscription_followerId, InboundSubscription.producerId
 AS InboundSubscription_producerId, InboundSubscription.status AS
 InboundSubscription_status, InboundSubscription.suspended AS
 InboundSubscription_suspended
 FROM InboundSubscription
 WHERE :param_1 = InboundSubscription.producerId
 
 When is this value populated? How can I access it in query_chooser?
 
 The bindparam() object should have a callable attribute - call that to get 
 the value.These values are late-bound when using lazyloading.
 
 -- 
 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.
 

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



[sqlalchemy] Re: query_chooser and relationship queries

2011-06-24 Thread Arthur Kopatsy
Great. Of course that line ( |    verificationTokenExpiry =
Column(String)) was a copy and paste mistake.

On Jun 24, 10:28 am, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 24, 2011, at 1:26 PM, Arthur Kopatsy wrote:

  Awesome.

  Does that mean the sqlalchemy example is wrong. It currently has:
         if callable(value):
             value = value()

 yeah thats out of date, usage  was changed in 0.7.

  Should it be something like that?

         if value == None and bind.callable !=
  None:
  |    verificationTokenExpiry = Column(String)
             value = bind.callable()

  Thank you so much for the quick response.

 yupwe had the same issue with beaker ill have to update this example









  Arthur

  On Jun 24, 10:05 am, Michael Bayer mike...@zzzcomputing.com wrote:
  On Jun 24, 2011, at 12:49 PM, Arthur Kopatsy wrote:

  Hi,

  I am trying to write a proper query_chooser method for our user based
  sharding. To do so, I need to be able to query the value of the
  query's criterions.

  I have the following model:
  class User(object):
     id = Column(Integer, primary_key=True)
     ...

  class Subscription(object):
     id = Column(Integer, primary_key=True)
     producerId = Column(Integer, ForeignKey('User.id'))
     consumerId = Column(Integer) # No foreign key because sharded on
  producerId
     producer = relationship('User', backref='subscriptions')

  In my query_chooser, I am using the code from the attribute_sharding
  example and try to find out the value of producerId if there is such a
  criterion.

  Given an existing myUser instance and a session, I see two different
  behaviors:

  1. session.query(Subscription).filter(Subscription.producerId ==
  myUser.id).all()

  I will get a proper value for producerId in the dictionary of bound
  parameters so I can find out the shard, no problem.

  SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
  InboundSubscription.active AS InboundSubscription_active,
  InboundSubscription.createdAt AS InboundSubscription_createdAt,
  InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
  InboundSubscription.followerId AS
  InboundSubscription_followerId, InboundSubscription.producerId
  AS InboundSubscription_producerId, InboundSubscription.status AS
  InboundSubscription_status, InboundSubscription.suspended AS
  InboundSubscription_suspended
  FROM InboundSubscription
  WHERE InboundSubscription.producerId = :producerId_1

  2. myUser.subscriptions

  I get a None value for the anonymous parameter which prevents me from
  picking a shard.

  SELECT InboundSubscription.s9id AS InboundSubscription_s9id,
  InboundSubscription.active AS InboundSubscription_active,
  InboundSubscription.createdAt AS InboundSubscription_createdAt,
  InboundSubscription.updatedAt AS InboundSubscription_updatedAt,
  InboundSubscription.followerId AS
  InboundSubscription_followerId, InboundSubscription.producerId
  AS InboundSubscription_producerId, InboundSubscription.status AS
  InboundSubscription_status, InboundSubscription.suspended AS
  InboundSubscription_suspended
  FROM InboundSubscription
  WHERE :param_1 = InboundSubscription.producerId

  When is this value populated? How can I access it in query_chooser?

  The bindparam() object should have a callable attribute - call that to 
  get the value.    These values are late-bound when using lazyloading.

  --
  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 
  athttp://groups.google.com/group/sqlalchemy?hl=en.

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



[sqlalchemy] Re: cascade_backrefs=False broken for many-to-many relationships?

2011-06-24 Thread Robert Rollins
Ahhh, ok!  I was missing two important bits of info:

1) I didn't know about the backref() function.  I was just using
backref='users' in my relationship() args.
2) Thus, I didn't realize that using cascade_backrefs=False as an arg
to relationship() would apply the setting in the wrong direction.

Using backref=backref('users', cascade_backrefs=False) has fixed my
problem.  Thanks for the quick response!

On Jun 23, 4:34 pm, Michael Bayer mike...@zzzcomputing.com wrote:
 On Jun 23, 2011, at 7:12 PM, Robert Rollins wrote:



  I'm using SQLAlchemy 0.7.1 on a MySQL 5.1.57 database, and I'm getting
  unexpected behavior with the cascade_backrefs=False parameter for my
  many-to-many relationships.

     groups = relationship(ZKGroup, secondary=user_groups,
  backref='users', cascade_backrefs=False)

     def __init__(self, username, groups)
         self.username = username
         self.groups = groups

  Now, I would expect the cascade_backrefs=False option to prevent newly
  created ZKUser objects with a persistent ZKGroup object in their
  'groups' list to not be added to the session.  But the ZKUser object
  appears to being getting added to the session anyway.  I can tell
  because this code:

  Is this a bug with cascade_backrefs=False? Or is it just not meant to
  be used with many-to-many relationships, or something like that?

 I was pretty sure this came down to which side you put the flag on, keeping 
 in mind that *I* didn't know which side it should be on.    Apparently its 
 the side that would be receiving cascades via a backref, not the one that 
 would be sending them:

     groups = relationship(ZKGroup,
                     secondary=user_groups,
                     backref=backref('users', cascade_backrefs=False))

 That is, the event is initiated by self.groups, which then hits group.users 
 on the backref, but then the new User is not cascaded due to the flag.

 The docstring for relationship() is accurate here, from the perspective that 
 the cascade_backrefs goes on the side that would be receiving the event, 
 not the one initiating it, but it only speaks in terms of 
 one-to-many/many-to-one, so even with all that typing I did it's still not 
 clear.   But with backref events, it doesn't really matter what type of 
 pattern is on each side.

 The documentation for the flag in the Session / Cascades section, well 
 looking there it looks like the mappings are nonsensical, geezfixing that 
 now.



  --
  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 
  athttp://groups.google.com/group/sqlalchemy?hl=en.

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



Re: [sqlalchemy] per-host pooling vs per-engine pooling

2011-06-24 Thread Tarek Ziadé
On Fri, Jun 24, 2011 at 7:04 PM, Michael Bayer mike...@zzzcomputing.com wrote:
...
 Is there a way to do it with the existing pools ?   If not, I guess
 I'll work on a custom Pool,

 well a pool is geared towards one specific connection which already has a 
 database set up on it.    I guess maybe you'd use pool events to switch the 
 database on checkout.

do you known if the switching can be done without closing the socket ?


 You can share a pool between engines using the pool argument to 
 create_engine(), but one problem with that right now is that the dialect 
 which is per-engine uses the on first checkout event to handle some 
 important dialect initialization.  That step would have to be accommodated in 
 some way.

 Also this solution is only local to one Python process, not even a fork.  You 
 might have a simpler time limiting TCP connections using a product like 
 PGBouncer, and turn pooling way down or off for each SQLAlchemy pool, that 
 way you can truly limit connections per host.

Ok thanks for the tip I'll investigate on this

Cheers
Tarek

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



Re: [sqlalchemy] call mysql procedure (as opposed to function) using sql expression language

2011-06-24 Thread Chris Withers

On 15/06/2011 19:13, Michael Bayer wrote:

session.execute('call myfunc()').scalar()

...but is there a way I can generate that?


i havent worked with MySQL sps but maybe there's a way to CREATE FUNCTION 
instead of SP, not sure, otherwise you'd probably want to do this:

class Call(ClauseElement):
 def __init__(self, name):
 self.name = name

@compiles(Call)
def _call(expression, compiler, **kw):
 return CALL %s % expression.name


Should this be in SA itself?

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk

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



Re: [sqlalchemy] per-host pooling vs per-engine pooling

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 2:51 PM, Tarek Ziadé wrote:

 On Fri, Jun 24, 2011 at 7:04 PM, Michael Bayer mike...@zzzcomputing.com 
 wrote:
 ...
 Is there a way to do it with the existing pools ?   If not, I guess
 I'll work on a custom Pool,
 
 well a pool is geared towards one specific connection which already has a 
 database set up on it.I guess maybe you'd use pool events to switch 
 the database on checkout.
 
 do you known if the switching can be done without closing the socket ?

yeah this is not a problem, if this is PG there's a default schema setting, i 
forget what it's called, with MySQL its use.

Also, I realized that if you set up the Pool on all the Engines at once before 
any connections occur, the on first connect event will get called for all of 
them, so you could get it to work that way.


 
 
 You can share a pool between engines using the pool argument to 
 create_engine(), but one problem with that right now is that the dialect 
 which is per-engine uses the on first checkout event to handle some 
 important dialect initialization.  That step would have to be accommodated 
 in some way.
 
 Also this solution is only local to one Python process, not even a fork.  
 You might have a simpler time limiting TCP connections using a product like 
 PGBouncer, and turn pooling way down or off for each SQLAlchemy pool, that 
 way you can truly limit connections per host.
 
 Ok thanks for the tip I'll investigate on this
 
 Cheers
 Tarek
 
 -- 
 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.
 

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



Re: [sqlalchemy] call mysql procedure (as opposed to function) using sql expression language

2011-06-24 Thread Michael Bayer

On Jun 24, 2011, at 3:22 PM, Chris Withers wrote:

 On 15/06/2011 19:13, Michael Bayer wrote:
 session.execute('call myfunc()').scalar()
 
 ...but is there a way I can generate that?
 
 i havent worked with MySQL sps but maybe there's a way to CREATE FUNCTION 
 instead of SP, not sure, otherwise you'd probably want to do this:
 
 class Call(ClauseElement):
 def __init__(self, name):
 self.name = name
 
 @compiles(Call)
 def _call(expression, compiler, **kw):
 return CALL %s % expression.name
 
 Should this be in SA itself?

shrugs, if its of general use, would be nice if it could do something useful 
for SQL server, oracle, etc.




 
 Chris
 
 -- 
 Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
 
 -- 
 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.
 

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