[sqlalchemy] Outer join question

2011-12-01 Thread Thierry Florac
Hi,

I have a little problem with outer joins (I use QSLAlchemy 0.5.6).

I have two tables, managing tasks and activities :

class Task(Base):
__tablename__ = 'tache'

id = Column(Integer, Sequence('seq_tache_id'), primary_key=True)
libelle = Column(Unicode(50))
description = Column(Unicode(4000))
...

class Activity(Base):
__tablename__ = 'activite'

id_ressource = Column(Integer, ForeignKey(Resource.id))
date_realisation = Column(Date)
id_tache_am = Column(Integer, ForeignKey(Task.id))
id_tache_pm = Column(Integer, ForeignKey(Task.id))

__table_args__ = (
PrimaryKeyConstraint('id_ressource', 'date_realisation'),
{}
)

Activity.task_am = relation(Task, primaryjoin=Activity.id_tache_am ==
Task.id, backref='activity_am')
Activity.task_pm = relation(Task, primaryjoin=Activity.id_tache_pm ==
Task.id, backref='activity_pm')


My problem is that I want to select activities and, for each of them,
their related AM and PM tasks labels (which can be null), as follow :

TaskAM = aliased(Task)
TaskPM = aliased(Task)
for activity, libelle_am, libelle_pm in
session.query(Activity, TaskAM.libelle, TaskPM.libelle) \

.outerjoin(TaskAM.activity_am, TaskPM.activity_pm) \

.filter(and_(Activity.id_ressource == User.getCurrentUser().id,

Activity.date_realisation.between(start_date, end_date))):
...

The generated SQL query is as follow :

SELECT projetsdi.activite.id_ressource AS
projetsdi_activite_id_re_1, ..., tache_1.libelle AS tache_1_libelle,
tache_2.libelle AS tache_2_libelle
FROM projetsdi.tache tache_2, projetsdi.tache tache_1 LEFT OUTER
JOIN projetsdi.activite ON projetsdi.activite.id_tache_am = tache_1.id
WHERE projetsdi.activite.id_ressource = :id_ressource_1 AND
projetsdi.activite.date_realisation BETWEEN :date_realisation_1 AND
:date_realisation_2

So this query only selects activities for which id_tache_am is defined !!
The good query should be something like :

SELECT ...
FROM projetsdi.activite
LEFT OUTER JOIN projetsdi.tache tache_1 ON
projetsdi.activite.id_tache_am = tache_1.id
LEFT OUTER JOIN projetsdi.tache tache_2 ON
projetsdi.activite.id_tache_pm = tache_2.id

Any idea about how to get such a result ??

Many thanks,
Thierry
-- 
http://www.imagesdusport.com -- http://www.ztfy.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] Column parameters: default=callable is working, but onupdate=callable is not.

2011-12-01 Thread Wubin
Hi,
I created two classes Resource and BaseMedia, and BaseMedia is a
subclass of Resource. The table mapping is implemented as below:

class Resource(Database.Base):
__tablename__ = resources
createUserId = Column(create_user_id, Integer,
ForeignKey(users.id), nullable=True, key=createUserId,
default=currentUserId)
modifyUserId = Column(modify_user_id, Integer,
ForeignKey(users.id), nullable=True, key=modifyUserId,
default=currentUserId, onupdate=currentUserId)

class BaseMedia(Resource.Resource):
__tablename__ = base_media
id = Column(id, Integer, ForeignKey(resources.id),
primary_key=True)
__mapper_args__ = { 'extension':
BaseMediaMapperExtension.BaseMediaMapperExtension() }
name = Column(name, Unicode(50))
type = Column(type, String(50))
size = Column(size, Integer)

and then, when I try to use session.add() to insert a new BaseMedia
object, the parameter default=currentUserId in both createUserId
and modifyUserId columns is working properly. However, if I use
session.merge() to update the name column in an existing BaseMedia
object, the name field is updated correctly in the database, but the
parameter onupdate=currentUserId is not firing, and therefore I
couldn't update the modifyUserId field with this onupdate
parameter.

The code is running with sqlalchemy 0.6.4, and there isn't any warning
or error message from it. I will appreciate if anyone can help me
solve this problem.

Wubin

-- 
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: Outer join question

2011-12-01 Thread Thierry Florac
Hi,

Problem is solved with last SQLAlchemy 0.7.6 !!
I was a little affrayed to change but only had minor incompatibilities :-)

For anybody interested, the good syntax is :

session.query(Activity, TaskAM.libelle, TaskPM.libelle) \
   .outerjoin(TaskAM, Activity.task_am) \
   .outerjoin(TaskPM, Activity.task_pm) \
   .filter(...)

Best regards,
Thierry


2011/12/1 Thierry Florac tflo...@gmail.com:
 Hi,

 I have a little problem with outer joins (I use QSLAlchemy 0.5.6).

 I have two tables, managing tasks and activities :

 class Task(Base):
    __tablename__ = 'tache'

    id = Column(Integer, Sequence('seq_tache_id'), primary_key=True)
    libelle = Column(Unicode(50))
    description = Column(Unicode(4000))
    ...

 class Activity(Base):
    __tablename__ = 'activite'

    id_ressource = Column(Integer, ForeignKey(Resource.id))
    date_realisation = Column(Date)
    id_tache_am = Column(Integer, ForeignKey(Task.id))
    id_tache_pm = Column(Integer, ForeignKey(Task.id))

    __table_args__ = (
        PrimaryKeyConstraint('id_ressource', 'date_realisation'),
        {}
    )

 Activity.task_am = relation(Task, primaryjoin=Activity.id_tache_am ==
 Task.id, backref='activity_am')
 Activity.task_pm = relation(Task, primaryjoin=Activity.id_tache_pm ==
 Task.id, backref='activity_pm')


 My problem is that I want to select activities and, for each of them,
 their related AM and PM tasks labels (which can be null), as follow :

        TaskAM = aliased(Task)
        TaskPM = aliased(Task)
        for activity, libelle_am, libelle_pm in
 session.query(Activity, TaskAM.libelle, TaskPM.libelle) \

 .outerjoin(TaskAM.activity_am, TaskPM.activity_pm) \

 .filter(and_(Activity.id_ressource == User.getCurrentUser().id,

 Activity.date_realisation.between(start_date, end_date))):
            ...

 The generated SQL query is as follow :

    SELECT projetsdi.activite.id_ressource AS
 projetsdi_activite_id_re_1, ..., tache_1.libelle AS tache_1_libelle,
 tache_2.libelle AS tache_2_libelle
    FROM projetsdi.tache tache_2, projetsdi.tache tache_1 LEFT OUTER
 JOIN projetsdi.activite ON projetsdi.activite.id_tache_am = tache_1.id
    WHERE projetsdi.activite.id_ressource = :id_ressource_1 AND
 projetsdi.activite.date_realisation BETWEEN :date_realisation_1 AND
 :date_realisation_2

 So this query only selects activities for which id_tache_am is defined !!
 The good query should be something like :

    SELECT ...
    FROM projetsdi.activite
        LEFT OUTER JOIN projetsdi.tache tache_1 ON
 projetsdi.activite.id_tache_am = tache_1.id
        LEFT OUTER JOIN projetsdi.tache tache_2 ON
 projetsdi.activite.id_tache_pm = tache_2.id

 Any idea about how to get such a result ??

 Many thanks,
 Thierry
 --
 http://www.imagesdusport.com -- http://www.ztfy.org



-- 
http://www.imagesdusport.com -- http://www.ztfy.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.



Re: [sqlalchemy] Re: Outer join question

2011-12-01 Thread Michael Bayer
you can probably do it in all versions including 0.5 just using two separate 
outerjoin calls:

outerjoin(Activity.task_am).\
outerjoin(Activity.task_pm)

each new call to outerjoin() starts back from the parent Activity.

the TaskAM/TaskPM targets can be implicit there.


On Dec 1, 2011, at 11:12 AM, Thierry Florac wrote:

 Hi,
 
 Problem is solved with last SQLAlchemy 0.7.6 !!
 I was a little affrayed to change but only had minor incompatibilities :-)
 
 For anybody interested, the good syntax is :
 
session.query(Activity, TaskAM.libelle, TaskPM.libelle) \
   .outerjoin(TaskAM, Activity.task_am) \
   .outerjoin(TaskPM, Activity.task_pm) \
   .filter(...)
 
 Best regards,
 Thierry
 
 
 2011/12/1 Thierry Florac tflo...@gmail.com:
 Hi,
 
 I have a little problem with outer joins (I use QSLAlchemy 0.5.6).
 
 I have two tables, managing tasks and activities :
 
 class Task(Base):
__tablename__ = 'tache'
 
id = Column(Integer, Sequence('seq_tache_id'), primary_key=True)
libelle = Column(Unicode(50))
description = Column(Unicode(4000))
...
 
 class Activity(Base):
__tablename__ = 'activite'
 
id_ressource = Column(Integer, ForeignKey(Resource.id))
date_realisation = Column(Date)
id_tache_am = Column(Integer, ForeignKey(Task.id))
id_tache_pm = Column(Integer, ForeignKey(Task.id))
 
__table_args__ = (
PrimaryKeyConstraint('id_ressource', 'date_realisation'),
{}
)
 
 Activity.task_am = relation(Task, primaryjoin=Activity.id_tache_am ==
 Task.id, backref='activity_am')
 Activity.task_pm = relation(Task, primaryjoin=Activity.id_tache_pm ==
 Task.id, backref='activity_pm')
 
 
 My problem is that I want to select activities and, for each of them,
 their related AM and PM tasks labels (which can be null), as follow :
 
TaskAM = aliased(Task)
TaskPM = aliased(Task)
for activity, libelle_am, libelle_pm in
 session.query(Activity, TaskAM.libelle, TaskPM.libelle) \
 
 .outerjoin(TaskAM.activity_am, TaskPM.activity_pm) \
 
 .filter(and_(Activity.id_ressource == User.getCurrentUser().id,
 
 Activity.date_realisation.between(start_date, end_date))):
...
 
 The generated SQL query is as follow :
 
SELECT projetsdi.activite.id_ressource AS
 projetsdi_activite_id_re_1, ..., tache_1.libelle AS tache_1_libelle,
 tache_2.libelle AS tache_2_libelle
FROM projetsdi.tache tache_2, projetsdi.tache tache_1 LEFT OUTER
 JOIN projetsdi.activite ON projetsdi.activite.id_tache_am = tache_1.id
WHERE projetsdi.activite.id_ressource = :id_ressource_1 AND
 projetsdi.activite.date_realisation BETWEEN :date_realisation_1 AND
 :date_realisation_2
 
 So this query only selects activities for which id_tache_am is defined !!
 The good query should be something like :
 
SELECT ...
FROM projetsdi.activite
LEFT OUTER JOIN projetsdi.tache tache_1 ON
 projetsdi.activite.id_tache_am = tache_1.id
LEFT OUTER JOIN projetsdi.tache tache_2 ON
 projetsdi.activite.id_tache_pm = tache_2.id
 
 Any idea about how to get such a result ??
 
 Many thanks,
 Thierry
 --
 http://www.imagesdusport.com -- http://www.ztfy.org
 
 
 
 -- 
 http://www.imagesdusport.com -- http://www.ztfy.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.
 

-- 
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] SqlAlchemy 0.6.8 Initiatior in AttributeExtension

2011-12-01 Thread Michael Bayer

On Nov 30, 2011, at 7:48 PM, Hector Blanco wrote:

 Hello everyone!
 
 I am using (yeah, still) SqlAlchemy 0.6.8 and I'm using an
 AttributeExtension to build permissions of users.
 
 
 class UserGroupExtension(AttributeExtension):
   def set(self, state, value, oldvalue, initiator):
   userToUpdate = # !!! do things here to get the user
   value.rebuildPermissions(userToUpdate)
return value
 
   def remove(self, state, value, initiator):
   removeAllThePermissionForUsersInGroup(value)
 
 
 So, in the UserGroupExtension, I need to get the user that fired the
 event, to apply the proper permissions to it.
 
 I've tried state.obj(), but that gives me an empty user.

The state object's obj() is the parent User object receiving the events. It 
should be the same identity as the User receiving the append.   The @validates 
decorator will get you the same effect with less boilerplate.

-- 
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] Column parameters: default=callable is working, but onupdate=callable is not.

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 1:32 AM, Wubin wrote:

 Hi,
 I created two classes Resource and BaseMedia, and BaseMedia is a
 subclass of Resource. The table mapping is implemented as below:
 
 class Resource(Database.Base):
   __tablename__ = resources
   createUserId = Column(create_user_id, Integer,
 ForeignKey(users.id), nullable=True, key=createUserId,
 default=currentUserId)
   modifyUserId = Column(modify_user_id, Integer,
 ForeignKey(users.id), nullable=True, key=modifyUserId,
 default=currentUserId, onupdate=currentUserId)
 
 class BaseMedia(Resource.Resource):
   __tablename__ = base_media
id = Column(id, Integer, ForeignKey(resources.id),
 primary_key=True)
   __mapper_args__ = { 'extension':
 BaseMediaMapperExtension.BaseMediaMapperExtension() }
   name = Column(name, Unicode(50))
   type = Column(type, String(50))
   size = Column(size, Integer)
 
 and then, when I try to use session.add() to insert a new BaseMedia
 object, the parameter default=currentUserId in both createUserId
 and modifyUserId columns is working properly. However, if I use
 session.merge() to update the name column in an existing BaseMedia
 object, the name field is updated correctly in the database, but the
 parameter onupdate=currentUserId is not firing, and therefore I
 couldn't update the modifyUserId field with this onupdate
 parameter.

Do you see an UPDATE occurring in the logs ?   The UPDATE statement should 
include a SET clause for the modifyUserId column unconditionally - the value in 
the parameter list might shed some light on what's actually happening.

Particularly with merge(), the value from the merged object is likely being 
passed as the new value of modifyUserId and that's what's being used.


-- 
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] bug in reflection.py sqla 0.7.3

2011-12-01 Thread Michael Bayer
I'm not able to reproduce that, and also this code should likely be replaced by 
our existing topological sort code.  Can you provide a succinct reproducing 
example ?


On Dec 1, 2011, at 2:22 AM, Robert Forkel wrote:

 Hi,
 trying to use Inspector.get_table_names with order_by='foreign_key'
 causes the following exception:
 
 Traceback (most recent call last):
  File db_inspector.py, line 20, in module
for table in insp.get_table_names(schema=schema,
 order_by='foreign_key'):
  File lib/python2.6/site-packages/sqlalchemy/engine/reflection.py,
 line 173, in get_table_names
ordered_tnames.index(ref_pos, tname)
 TypeError: slice indices must be integers or None or have an __index__
 method
 
 which can be remdied by the following patch:
 
 (gulpenv)$ diff -crB lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py.orig*** lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py 2011-12-01 08:15:01.600838080 +0100
 --- lib/python2.6/site-packages/sqlalchemy/engine/reflection.py.orig
 2011-12-01 08:14:40.980828074 +0100
 ***
 *** 169,175 
  if table_pos  ref_pos:
  ordered_tnames.pop(table_pos) # rtable
 moves up 1
  # insert just below rtable
 ! ordered_tnames.insert(ref_pos, tname)
  tnames = ordered_tnames
  return tnames
 
 --- 169,175 
  if table_pos  ref_pos:
  ordered_tnames.pop(table_pos) # rtable
 moves up 1
  # insert just below rtable
 ! ordered_tnames.index(ref_pos, tname)
  tnames = ordered_tnames
  return tnames
 
 best regards
 robert
 
 -- 
 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] bug in reflection.py sqla 0.7.3

2011-12-01 Thread Michael Bayer
nevermind, I need to randomize that list in order to trigger it


On Dec 1, 2011, at 1:42 PM, Michael Bayer wrote:

 I'm not able to reproduce that, and also this code should likely be replaced 
 by our existing topological sort code.  Can you provide a succinct 
 reproducing example ?
 
 
 On Dec 1, 2011, at 2:22 AM, Robert Forkel wrote:
 
 Hi,
 trying to use Inspector.get_table_names with order_by='foreign_key'
 causes the following exception:
 
 Traceback (most recent call last):
 File db_inspector.py, line 20, in module
   for table in insp.get_table_names(schema=schema,
 order_by='foreign_key'):
 File lib/python2.6/site-packages/sqlalchemy/engine/reflection.py,
 line 173, in get_table_names
   ordered_tnames.index(ref_pos, tname)
 TypeError: slice indices must be integers or None or have an __index__
 method
 
 which can be remdied by the following patch:
 
 (gulpenv)$ diff -crB lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py.orig*** lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py2011-12-01 08:15:01.600838080 +0100
 --- lib/python2.6/site-packages/sqlalchemy/engine/reflection.py.orig
 2011-12-01 08:14:40.980828074 +0100
 ***
 *** 169,175 
 if table_pos  ref_pos:
 ordered_tnames.pop(table_pos) # rtable
 moves up 1
 # insert just below rtable
 ! ordered_tnames.insert(ref_pos, tname)
 tnames = ordered_tnames
 return tnames
 
 --- 169,175 
 if table_pos  ref_pos:
 ordered_tnames.pop(table_pos) # rtable
 moves up 1
 # insert just below rtable
 ! ordered_tnames.index(ref_pos, tname)
 tnames = ordered_tnames
 return tnames
 
 best regards
 robert
 
 -- 
 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.



Re: [sqlalchemy] Column parameters: default=callable is working, but onupdate=callable is not.

2011-12-01 Thread Wubin Chin
Hi Michael,
Thank you for the reply, the logs I got from the sqlalchemy shown as below:

2011-12-01 13:53:49,062 INFO sqlalchemy.engine.base.Engine.0x...29cc UPDATE
base_media SET name=%s WHERE base_media.id = %s
2011-12-01 13:53:49,062 INFO [sqlalchemy.engine.base.Engine.0x...29cc]
UPDATE base_media SET name=%s WHERE base_media.id = %s
2011-12-01 13:53:49,063 INFO sqlalchemy.engine.base.Engine.0x...29cc
('waucissa2.mov', 42L)
2011-12-01 13:53:49,063 INFO [sqlalchemy.engine.base.Engine.0x...29cc]
('waucissa2.mov', 42L)
2011-12-01 13:53:49,066 INFO sqlalchemy.engine.base.Engine.0x...29cc INSERT
INTO interm_hidden_vsblzrs_to_resources (element_id, base_visibilizer_id)
VALUES (%s, %s)
2011-12-01 13:53:49,066 INFO [sqlalchemy.engine.base.Engine.0x...29cc]
INSERT INTO interm_hidden_vsblzrs_to_resources (element_id,
base_visibilizer_id) VALUES (%s, %s)
2011-12-01 13:53:49,066 INFO sqlalchemy.engine.base.Engine.0x...29cc (42L,
5L)
2011-12-01 13:53:49,066 INFO [sqlalchemy.engine.base.Engine.0x...29cc]
(42L, 5L)
2011-12-01 13:53:49,067 INFO sqlalchemy.engine.base.Engine.0x...29cc COMMIT
2011-12-01 13:53:49,067 INFO [sqlalchemy.engine.base.Engine.0x...29cc]
COMMIT

As you see, sqlalchemy only updated the name field in the base_media table,
so the onupdate=callable should be firing since the modifyUserId column
was not being touched. I will appreciate if you would give some suggestions
on it. By the way, I am using 0.6.8, not 0.6.4. Thank you very much!

Wubin


On Thu, Dec 1, 2011 at 1:25 PM, Michael Bayer mike...@zzzcomputing.comwrote:


 On Dec 1, 2011, at 1:32 AM, Wubin wrote:

  Hi,
  I created two classes Resource and BaseMedia, and BaseMedia is a
  subclass of Resource. The table mapping is implemented as below:
 
  class Resource(Database.Base):
__tablename__ = resources
createUserId = Column(create_user_id, Integer,
  ForeignKey(users.id), nullable=True, key=createUserId,
  default=currentUserId)
modifyUserId = Column(modify_user_id, Integer,
  ForeignKey(users.id), nullable=True, key=modifyUserId,
  default=currentUserId, onupdate=currentUserId)
 
  class BaseMedia(Resource.Resource):
__tablename__ = base_media
 id = Column(id, Integer, ForeignKey(resources.id),
  primary_key=True)
__mapper_args__ = { 'extension':
  BaseMediaMapperExtension.BaseMediaMapperExtension() }
name = Column(name, Unicode(50))
type = Column(type, String(50))
size = Column(size, Integer)
 
  and then, when I try to use session.add() to insert a new BaseMedia
  object, the parameter default=currentUserId in both createUserId
  and modifyUserId columns is working properly. However, if I use
  session.merge() to update the name column in an existing BaseMedia
  object, the name field is updated correctly in the database, but the
  parameter onupdate=currentUserId is not firing, and therefore I
  couldn't update the modifyUserId field with this onupdate
  parameter.

 Do you see an UPDATE occurring in the logs ?   The UPDATE statement should
 include a SET clause for the modifyUserId column unconditionally - the
 value in the parameter list might shed some light on what's actually
 happening.

 Particularly with merge(), the value from the merged object is likely
 being passed as the new value of modifyUserId and that's what's being used.


 --
 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] bug in reflection.py sqla 0.7.3

2011-12-01 Thread Michael Bayer
thats fixed in r2b66b5abf755,  will be in 0.7.4 or you can get the tip off the 
download page.




On Dec 1, 2011, at 1:47 PM, Michael Bayer wrote:

 nevermind, I need to randomize that list in order to trigger it
 
 
 On Dec 1, 2011, at 1:42 PM, Michael Bayer wrote:
 
 I'm not able to reproduce that, and also this code should likely be replaced 
 by our existing topological sort code.  Can you provide a succinct 
 reproducing example ?
 
 
 On Dec 1, 2011, at 2:22 AM, Robert Forkel wrote:
 
 Hi,
 trying to use Inspector.get_table_names with order_by='foreign_key'
 causes the following exception:
 
 Traceback (most recent call last):
 File db_inspector.py, line 20, in module
  for table in insp.get_table_names(schema=schema,
 order_by='foreign_key'):
 File lib/python2.6/site-packages/sqlalchemy/engine/reflection.py,
 line 173, in get_table_names
  ordered_tnames.index(ref_pos, tname)
 TypeError: slice indices must be integers or None or have an __index__
 method
 
 which can be remdied by the following patch:
 
 (gulpenv)$ diff -crB lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py.orig*** lib/python2.6/site-packages/sqlalchemy/engine/
 reflection.py   2011-12-01 08:15:01.600838080 +0100
 --- lib/python2.6/site-packages/sqlalchemy/engine/reflection.py.orig
 2011-12-01 08:14:40.980828074 +0100
 ***
 *** 169,175 
if table_pos  ref_pos:
ordered_tnames.pop(table_pos) # rtable
 moves up 1
# insert just below rtable
 ! ordered_tnames.insert(ref_pos, tname)
tnames = ordered_tnames
return tnames
 
 --- 169,175 
if table_pos  ref_pos:
ordered_tnames.pop(table_pos) # rtable
 moves up 1
# insert just below rtable
 ! ordered_tnames.index(ref_pos, tname)
tnames = ordered_tnames
return tnames
 
 best regards
 robert
 
 -- 
 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.
 

-- 
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] Column parameters: default=callable is working, but onupdate=callable is not.

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 1:32 AM, Wubin wrote:

 Hi,
 I created two classes Resource and BaseMedia, and BaseMedia is a
 subclass of Resource. The table mapping is implemented as below:
 
 class Resource(Database.Base):
   __tablename__ = resources
   createUserId = Column(create_user_id, Integer,
 ForeignKey(users.id), nullable=True, key=createUserId,
 default=currentUserId)
   modifyUserId = Column(modify_user_id, Integer,
 ForeignKey(users.id), nullable=True, key=modifyUserId,
 default=currentUserId, onupdate=currentUserId)
 
 class BaseMedia(Resource.Resource):
   __tablename__ = base_media
id = Column(id, Integer, ForeignKey(resources.id),
 primary_key=True)
   __mapper_args__ = { 'extension':
 BaseMediaMapperExtension.BaseMediaMapperExtension() }
   name = Column(name, Unicode(50))
   type = Column(type, String(50))
   size = Column(size, Integer)
 
 and then, when I try to use session.add() to insert a new BaseMedia
 object, the parameter default=currentUserId in both createUserId
 and modifyUserId columns is working properly. However, if I use
 session.merge() to update the name column in an existing BaseMedia
 object, the name field is updated correctly in the database, but the

name is on the base_media table, not resources, so no onupdate proceeds 
when only columns against base_media are modified.

onupdate is mostly used for timestamp columns to log when a row was last 
modified.  Using it to set integer foreign key values seems pretty questionable.


-- 
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] SqlAlchemy 0.6.8 Initiatior in AttributeExtension

2011-12-01 Thread Hector Blanco
@validates... Where have you been? Oh... In the documentation, all
along. The day I learn to read, I'll conquer the world

It works great. Thank you!

2011/12/1 Michael Bayer mike...@zzzcomputing.com:

 On Nov 30, 2011, at 7:48 PM, Hector Blanco wrote:

 Hello everyone!

 I am using (yeah, still) SqlAlchemy 0.6.8 and I'm using an
 AttributeExtension to build permissions of users.


 class UserGroupExtension(AttributeExtension):
       def set(self, state, value, oldvalue, initiator):
               userToUpdate = # !!! do things here to get the user
               value.rebuildPermissions(userToUpdate)
                return value

       def remove(self, state, value, initiator):
               removeAllThePermissionForUsersInGroup(value)
 

 So, in the UserGroupExtension, I need to get the user that fired the
 event, to apply the proper permissions to it.

 I've tried state.obj(), but that gives me an empty user.

 The state object's obj() is the parent User object receiving the events. It 
 should be the same identity as the User receiving the append.   The 
 @validates decorator will get you the same effect with less boilerplate.

 --
 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] Column parameters: default=callable is working, but onupdate=callable is not.

2011-12-01 Thread Wu-bin Zhen
Hi Michael,

I really appreciate your quick reply, and that you made me clear for this
issue.
Actually my goal is to log when an object was last modified, and who did
it. So I guess I need to use MapperExtension to implement this.

Thank you very much, and have a nice day.

On Thu, Dec 1, 2011 at 2:32 PM, Michael Bayer mike...@zzzcomputing.comwrote:


 On Dec 1, 2011, at 1:32 AM, Wubin wrote:

  Hi,
  I created two classes Resource and BaseMedia, and BaseMedia is a
  subclass of Resource. The table mapping is implemented as below:
 
  class Resource(Database.Base):
__tablename__ = resources
createUserId = Column(create_user_id, Integer,
  ForeignKey(users.id), nullable=True, key=createUserId,
  default=currentUserId)
modifyUserId = Column(modify_user_id, Integer,
  ForeignKey(users.id), nullable=True, key=modifyUserId,
  default=currentUserId, onupdate=currentUserId)
 
  class BaseMedia(Resource.Resource):
__tablename__ = base_media
 id = Column(id, Integer, ForeignKey(resources.id),
  primary_key=True)
__mapper_args__ = { 'extension':
  BaseMediaMapperExtension.BaseMediaMapperExtension() }
name = Column(name, Unicode(50))
type = Column(type, String(50))
size = Column(size, Integer)
 
  and then, when I try to use session.add() to insert a new BaseMedia
  object, the parameter default=currentUserId in both createUserId
  and modifyUserId columns is working properly. However, if I use
  session.merge() to update the name column in an existing BaseMedia
  object, the name field is updated correctly in the database, but the

 name is on the base_media table, not resources, so no onupdate
 proceeds when only columns against base_media are modified.

 onupdate is mostly used for timestamp columns to log when a row was last
 modified.  Using it to set integer foreign key values seems pretty
 questionable.


 --
 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] SA doesn't update table

2011-12-01 Thread Geo
Well, my case is a bit different. I'm writing a nightly running batch 
script. And this script is not running inside pyramid context, which means 
it is not the model that called from the framework. Instead, I arrange it 
to run by system cron. But, I'm trying to utilize the pyramid environment 
settings, like the development.ini and production.ini to get the connection 
string and the contextual/thread-local session management object 
ZopeTransactionExtension*. *I'm not sure if this is the best practice of 
doing in this way*,* may be I should just use the plain session object. For 
my understanding, it's the framework's responsibility to commit or abort 
session if using the thread-local session. That is way I manually put them 
in the code. So anyway I would like to know the reason that why the SA 
doesn't do anything in this case.* *And I was suspecting it is the reason 
of the complex joins in usage, because I have other code that doing things 
in the same way, they are just some simple single table queries, so*
*

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/1C4382KS8WoJ.
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] Strange update problem...

2011-12-01 Thread Thierry Florac
Hi,

Another quite strange problem using SQLAlchemy...
I've created two classes, with matching interfaces build with
zope.interface and zope.schema packages ; a web form is build with
z3c.form package ; everything is fine !

My problem is quite simple to describe : I have a main class which is
a Task, with a many-to-many relation to a Resource class ; nothing
complicated !

  class Task(Base):
implements(ITask)
id = Column(Integer, primary_key=True)
...

  class Resource(Base):
implements(IResource)
id = Column(Integer, primary_key=True)
...

  class Affectation(Base):
task_id = Column(Integer, ForeignKey(Task.id)
task = relation(Task)
resource_id = Column(Integer, ForeignKey(Resource.id)
resource = relation(Resource)

  Task.affectations = relation(Affectation)


Web creation/update forms are generated and working correctly (checked
via debugger on validation), but :
 - when I create a new task, everything is saved correctly in database
on commit ;
 - when I update an existing task and modify resources list,
everything is saved correctly ;
 - when I update an existing task and DON'T MODIFY resources list,
updates are NOT saved !!
 - if I remove resources assignment widget from the form and modify an
existing task, updates ARE saved !!

So it seems that when resources are in the form and NOT modified, the
matching task is not flagged dirty and is not saved in database. I
just don't understand why !!!

Any idea would be of great help !!!

Best regards,
Thierry
-- 
http://www.imagesdusport.com -- http://www.ztfy.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.



Re: [sqlalchemy] SA doesn't update table

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 4:29 PM, Geo wrote:

  And I was suspecting it is the reason of the complex joins in usage, because 
 I have other code that doing things in the same way,

the structure of the Query/ SELECT statement that gets you back some data has 
no connection on how that data behaves later on.   Your original case seems a 
simple case of the session being closed prematurely.


-- 
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] Strange update problem...

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 5:38 PM, Thierry Florac wrote:

 Hi,
 
 So it seems that when resources are in the form and NOT modified, the
 matching task is not flagged dirty and is not saved in database. I
 just don't understand why !!!

Only a full usage example would make it clear in this case.Again (like 
another email) it sounds like objects are not necessarily attached to any 
session in all cases.

-- 
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] Strange update problem...

2011-12-01 Thread Thierry Florac
2011/12/2 Michael Bayer mike...@zzzcomputing.com:

 On Dec 1, 2011, at 5:38 PM, Thierry Florac wrote:

 Hi,

 So it seems that when resources are in the form and NOT modified, the
 matching task is not flagged dirty and is not saved in database. I
 just don't understand why !!!

 Only a full usage example would make it clear in this case.    Again (like 
 another email) it sounds like objects are not necessarily attached to any 
 session in all cases.

OK.
I'll check my code another time and will send you my full example on
tomorrow morning when I'll be back at work.
But as you say, how can I :
 - check if an object is actually attached to a session ?
 - if not (but how could it be ?), attach it to the session ??

Many thanks for your help !!

Best regards,
Thierry

-- 
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] Strange update problem...

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 7:09 PM, Thierry Florac wrote:

 2011/12/2 Michael Bayer mike...@zzzcomputing.com:
 
 On Dec 1, 2011, at 5:38 PM, Thierry Florac wrote:
 
 Hi,
 
 So it seems that when resources are in the form and NOT modified, the
 matching task is not flagged dirty and is not saved in database. I
 just don't understand why !!!
 
 Only a full usage example would make it clear in this case.Again (like 
 another email) it sounds like objects are not necessarily attached to any 
 session in all cases.
 
 OK.
 I'll check my code another time and will send you my full example on
 tomorrow morning when I'll be back at work.
 But as you say, how can I :
 - check if an object is actually attached to a session ?
 - if not (but how could it be ?), attach it to the session ??

hopefully that will be all you need to debug, you can say obj in session, 
obj in session.new, some info on this at 
http://www.sqlalchemy.org/docs/orm/session.html#session-attributes 


-- 
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] Passing additional arguments to event listeners ?

2011-12-01 Thread Łukasz Czuja
Hi,

I do not see anywhere in the docs a way to pass custom attributes to
event listeners:

event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
kwarg1 = 'value', kwarg2 = 'value2')

so that the before_insert_listener can have mixed signature:

def before_insert_listener(mapper, connection, target, arg1, *args,
**kwargs):

the only other solution would be to store extra processing information
on the 'target' itself.

Should be reasonable if there is not another way to pass around
arguments. Should I open a ticket then?

Thanks

-- 
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] Passing additional arguments to event listeners ?

2011-12-01 Thread Michael Bayer

On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote:

 Hi,
 
 I do not see anywhere in the docs a way to pass custom attributes to
 event listeners:
 
 event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
 kwarg1 = 'value', kwarg2 = 'value2')
 
 so that the before_insert_listener can have mixed signature:
 
 def before_insert_listener(mapper, connection, target, arg1, *args,
 **kwargs):
 
 the only other solution would be to store extra processing information
 on the 'target' itself.
 
 Should be reasonable if there is not another way to pass around
 arguments. Should I open a ticket then?

this kind of pollutes the API with kwargs that might be needed for the listen() 
function itself someday, these are external use cases that are easily handled 
in Python:

def before_insert_listener(arg1, arg2, k1='value', k2='value'):
def before_insert(mapper, conn, target):
... body
return before_insert

event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', 
k2='y'))


-- 
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] Passing additional arguments to event listeners ?

2011-12-01 Thread Tate Kim
How about functools.partial ?
As far as I know, functools.partial will simply do this.

Usually, I import this when I need to make an argument-less function equip 
extra arguments.

  
Best regards,
Tate
-Original Message-
From: Michael Bayer mike...@zzzcomputing.com
Sender: sqlalchemy@googlegroups.com
Date: Thu, 1 Dec 2011 19:52:15 
To: sqlalchemy@googlegroups.com
Reply-To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?


On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote:

 Hi,
 
 I do not see anywhere in the docs a way to pass custom attributes to
 event listeners:
 
 event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
 kwarg1 = 'value', kwarg2 = 'value2')
 
 so that the before_insert_listener can have mixed signature:
 
 def before_insert_listener(mapper, connection, target, arg1, *args,
 **kwargs):
 
 the only other solution would be to store extra processing information
 on the 'target' itself.
 
 Should be reasonable if there is not another way to pass around
 arguments. Should I open a ticket then?

this kind of pollutes the API with kwargs that might be needed for the listen() 
function itself someday, these are external use cases that are easily handled 
in Python:

def before_insert_listener(arg1, arg2, k1='value', k2='value'):
def before_insert(mapper, conn, target):
... body
return before_insert

event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', 
k2='y'))


-- 
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] Passing additional arguments to event listeners ?

2011-12-01 Thread Jackson, Cameron
Not sure if this helps or not, but how about using a lambda that that calls 
your function with the arguments you want? This is the solution I've been using 
for passing arguments to wxPython event handlers. This tutorial might help: 
http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks 

-Original Message-
From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On 
Behalf Of Tate Kim
Sent: Friday, 2 December 2011 12:33 PM
To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?

How about functools.partial ?
As far as I know, functools.partial will simply do this.

Usually, I import this when I need to make an argument-less function equip 
extra arguments.

  
Best regards,
Tate
-Original Message-
From: Michael Bayer mike...@zzzcomputing.com
Sender: sqlalchemy@googlegroups.com
Date: Thu, 1 Dec 2011 19:52:15 
To: sqlalchemy@googlegroups.com
Reply-To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?


On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote:

 Hi,
 
 I do not see anywhere in the docs a way to pass custom attributes to
 event listeners:
 
 event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
 kwarg1 = 'value', kwarg2 = 'value2')
 
 so that the before_insert_listener can have mixed signature:
 
 def before_insert_listener(mapper, connection, target, arg1, *args,
 **kwargs):
 
 the only other solution would be to store extra processing information
 on the 'target' itself.
 
 Should be reasonable if there is not another way to pass around
 arguments. Should I open a ticket then?

this kind of pollutes the API with kwargs that might be needed for the listen() 
function itself someday, these are external use cases that are easily handled 
in Python:

def before_insert_listener(arg1, arg2, k1='value', k2='value'):
def before_insert(mapper, conn, target):
... body
return before_insert

event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', 
k2='y'))


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



-
DISCLAIMER: This e-mail transmission and any documents, files and 
previous e-mail messages attached to it are private and confidential.  
They may contain proprietary or copyright material or information that 
is subject to legal professional privilege.  They are for the use of 
the intended recipient only.  Any unauthorised viewing, use, disclosure, 
copying, alteration, storage or distribution of, or reliance on, this 
message is strictly prohibited.  No part may be reproduced, adapted or 
transmitted without the written permission of the owner.  If you have 
received this transmission in error, or are not an authorised recipient, 
please immediately notify the sender by return email, delete this 
message and all copies from your e-mail system, and destroy any printed 
copies.  Receipt by anyone other than the intended recipient should not 
be deemed a waiver of any privilege or protection.  Thales Australia 
does not warrant or represent that this e-mail or any documents, files 
and previous e-mail messages attached are error or virus free.  

-

-- 
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] SA doesn't update table

2011-12-01 Thread Geo
Ok I found the solution, just move the first query into the transaction 
body:

import transaction

try:
   transaction.begin()
   x_members = session.query(Distributor)...
   for member in x_members:
.
except:
  transaction.abort()
BTW, I'm using pyramid framework, which is using the following statement to 
init the session:

DBSession = scoped_session(sessionmaker(
 extension=ZopeTransactionExtension()))


-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/sqlalchemy/-/DAKuaGyKwM8J.
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] Passing additional arguments to event listeners ?

2011-12-01 Thread Tate Kim
Yes, I think also lambda can be good one.

Though lambda reduces an effort to type a predefined function, 
functools.partial is a bit familiar to me.


Best regards,
Tate
-Original Message-
From: Jackson, Cameron cameron.jack...@thalesgroup.com.au
Sender: sqlalchemy@googlegroups.com
Date: Fri, 2 Dec 2011 12:44:26 
To: sqlalchemy@googlegroups.comsqlalchemy@googlegroups.com
Reply-To: sqlalchemy@googlegroups.com
Subject: RE: [sqlalchemy] Passing additional arguments to event listeners ?

Not sure if this helps or not, but how about using a lambda that that calls 
your function with the arguments you want? This is the solution I've been using 
for passing arguments to wxPython event handlers. This tutorial might help: 
http://wiki.wxpython.org/Passing%20Arguments%20to%20Callbacks 

-Original Message-
From: sqlalchemy@googlegroups.com [mailto:sqlalchemy@googlegroups.com] On 
Behalf Of Tate Kim
Sent: Friday, 2 December 2011 12:33 PM
To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?

How about functools.partial ?
As far as I know, functools.partial will simply do this.

Usually, I import this when I need to make an argument-less function equip 
extra arguments.

  
Best regards,
Tate
-Original Message-
From: Michael Bayer mike...@zzzcomputing.com
Sender: sqlalchemy@googlegroups.com
Date: Thu, 1 Dec 2011 19:52:15 
To: sqlalchemy@googlegroups.com
Reply-To: sqlalchemy@googlegroups.com
Subject: Re: [sqlalchemy] Passing additional arguments to event listeners ?


On Dec 1, 2011, at 7:24 PM, Łukasz Czuja wrote:

 Hi,
 
 I do not see anywhere in the docs a way to pass custom attributes to
 event listeners:
 
 event.listen(cls, 'before_insert', before_insert_listener, arg1, arg2,
 kwarg1 = 'value', kwarg2 = 'value2')
 
 so that the before_insert_listener can have mixed signature:
 
 def before_insert_listener(mapper, connection, target, arg1, *args,
 **kwargs):
 
 the only other solution would be to store extra processing information
 on the 'target' itself.
 
 Should be reasonable if there is not another way to pass around
 arguments. Should I open a ticket then?

this kind of pollutes the API with kwargs that might be needed for the listen() 
function itself someday, these are external use cases that are easily handled 
in Python:

def before_insert_listener(arg1, arg2, k1='value', k2='value'):
def before_insert(mapper, conn, target):
... body
return before_insert

event.listen(cls, 'before_insert', before_insert_listener(arg1, arg2, k1='x', 
k2='y'))


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



-
DISCLAIMER: This e-mail transmission and any documents, files and 
previous e-mail messages attached to it are private and confidential.  
They may contain proprietary or copyright material or information that 
is subject to legal professional privilege.  They are for the use of 
the intended recipient only.  Any unauthorised viewing, use, disclosure, 
copying, alteration, storage or distribution of, or reliance on, this 
message is strictly prohibited.  No part may be reproduced, adapted or 
transmitted without the written permission of the owner.  If you have 
received this transmission in error, or are not an authorised recipient, 
please immediately notify the sender by return email, delete this 
message and all copies from your e-mail system, and destroy any printed 
copies.  Receipt by anyone other than the intended recipient should not 
be deemed a waiver of any privilege or protection.  Thales Australia 
does not warrant or represent that this e-mail or any documents, files 
and previous e-mail messages attached are error or virus free.  

-

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