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 [email protected].
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.

Reply via email to