[sqlalchemy] Re: object_session(remote_device_object) returns noneType

2008-10-13 Thread Heston James - Cold Beans
Michael,

 

Thanks for confirming that, seems it was a strong reference to the session
which was a local function variable, if was being destroyed and
unreferencing my object.

 

I'll look at ways to combat that ;-)

 

Cheers,

 

Heston

 

From: sqlalchemy@googlegroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Michael Bayer
Sent: 10 October 2008 15:25
To: sqlalchemy@googlegroups.com
Subject: [sqlalchemy] Re: object_session(remote_device_object) returns
noneType

 

 

On Oct 10, 2008, at 8:03 AM, Heston James - Cold Beans wrote:





Morning guys,

 

When calling object_session(my_object), it returns a NoneType object so I'm
unable to call commit() and close() on the session, what does this mean?
Does it mean my object is not attached to a session?

 

My understanding is that if I did something like:

 

my_object = session.query(object).get(object_id)

 

then pass my_object around the application and wish to commit its session I
should be able to use the object_session() method to do that? Is that not
correct?

 

 

that is all correct, however if you remove all strong references to the
session, it gets garbage collected and the objects are detached.

 



 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 6:41 AM, [EMAIL PROTECTED] wrote:


 why i cannot give in_() a bindparam?

 q.filter( x.in_( somelistorset )) works
 q.filter( x.in_( bindparam('somename') )) fails
 ...
 File sqlalchemy/sql/expression.py, line 1368, in _in_impl
 for o in seq_or_selectable:
 TypeError: '_BindParamClause' object is not iterable

 is this possible or not ?
 or sending a list/tuple/iterable as bindparam-value is not supported?


is this a resend?   I answered a week ago (hm, GG didnt  
deliver ?  )should be x.in_([bindparam('somename')])

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] connect data base

2008-10-13 Thread nano

hello,
I'm new to sqlalchemy and database
I just installed postgres http://doc.fedora-fr.org/wiki/
Installation_et_configuration_de_PostgreSQL,
and I have a problem connecting to my database
with a script sqlalchemy
the error is   File/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.0-
py2.4.egg/sqlalchemy/engine/strategies.py, line 77, in connect raise
exceptions.DBAPIError.instance(None, None, e)
sqlalchemy.exceptions.OperationalError: (OperationalError) FATAL:
Ident authentication failed for user postgres None None.
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread Wayne Witzel



On Oct 13, 6:41 am, [EMAIL PROTECTED] wrote:
 why i cannot give in_() a bindparam?   

 q.filter( x.in_( somelistorset )) works
 q.filter( x.in_( bindparam('somename') )) fails
 ...
 File sqlalchemy/sql/expression.py, line 1368, in _in_impl
     for o in seq_or_selectable:
 TypeError: '_BindParamClause' object is not iterable

 is this possible or not ?
 or sending a list/tuple/iterable as bindparam-value is not supported?

 ciao
 svil

Just wrap your bindparam with brackets.

Wayne
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread Wayne Witzel



On Oct 13, 10:21 am, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 13, 2008, at 6:41 AM, [EMAIL PROTECTED] wrote:



  why i cannot give in_() a bindparam?

  q.filter( x.in_( somelistorset )) works
  q.filter( x.in_( bindparam('somename') )) fails
  ...
  File sqlalchemy/sql/expression.py, line 1368, in _in_impl
      for o in seq_or_selectable:
  TypeError: '_BindParamClause' object is not iterable

  is this possible or not ?
  or sending a list/tuple/iterable as bindparam-value is not supported?

 is this a resend?   I answered a week ago (hm, GG didnt  
 deliver ?  )    should be x.in_([bindparam('somename')])

I have to turn off the caching proxy for this group, you reply too
fast.

Wayne
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: connect data base

2008-10-13 Thread Werner F. Bruhin

nano wrote:
 hello,
 I'm new to sqlalchemy and database
 I just installed postgres http://doc.fedora-fr.org/wiki/
 Installation_et_configuration_de_PostgreSQL,
 and I have a problem connecting to my database
 with a script sqlalchemy
 the error is   File/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.0-
 py2.4.egg/sqlalchemy/engine/strategies.py, line 77, in connect raise
 exceptions.DBAPIError.instance(None, None, e)
 sqlalchemy.exceptions.OperationalError: (OperationalError) FATAL:
 Ident authentication failed for user postgres None None.
 Thanks.
   
No expert in SA, but if you just start with it I would suggest going 
with version 5, i.e. 0.5rc2 just came out the other day.

Have you installed psycopg2?  The DB-API you need for PostGres.

Showing a little of your script might also help.

You might also find answers in the SA doc, which is pretty good (and I 
always forget to look into it too ;-) ).

http://www.sqlalchemy.org/docs/05/intro.html

I would also look at declarative, I found it easier to define my db model.

http://www.sqlalchemy.org/docs/05/ormtutorial.html#datamapping_declarative

Hope this helps
Werner

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread az

On Monday 13 October 2008 17:21:31 Michael Bayer wrote:
 On Oct 13, 2008, at 6:41 AM, [EMAIL PROTECTED] wrote:
  why i cannot give in_() a bindparam?
 
  q.filter( x.in_( somelistorset )) works
  q.filter( x.in_( bindparam('somename') )) fails
  ...
  File sqlalchemy/sql/expression.py, line 1368, in _in_impl
  for o in seq_or_selectable:
  TypeError: '_BindParamClause' object is not iterable
 
  is this possible or not ?
  or sending a list/tuple/iterable as bindparam-value is not
  supported?

 is this a resend?   I answered a week ago (hm, GG didnt
 deliver ?  )
didnt...
 should be x.in_([bindparam('somename')]) 
but that is a list containing one param. 
i want the whole list to be a parameter.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Passing a param that is a list to execute()

2008-10-13 Thread Jonathan Marshall

Hi,

I'm not sure whether this is a bug in sqlalchemy or user error. I'm
having trouble passing a parameter to execute() that is a list of
values for the in operator.

E.g.:
  session.execute(sql.text('SELECT * from users where x in :xs'),
params={'xs' : some_seq})

This works fine when using MySQL so long as some_seq is a list of
integers. It does not return the correct results if some_seq is a list
of strings. It always fails with OperationalError when using sqlite.

The in_ operator works correctly however my application needs to
support text SQL input.

Any ideas?

Thanks.
Jon.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] similar to composite()

2008-10-13 Thread g00fy

I have my table Warehouse collumns like:
id, owner_id  , area_total, area_office ... ,area_storage
I would like to have acces to all areas by Warehouse.area.property:
example:
Warehouse.area.storage

I did composite(), but now I can't filter like:
filter(Warehouse.area.total =100) and even not by
fitler(Warehouse.area_total =100)

but i can access
Warehouse.area.total

I don't want to create aditional Area table, becouse that will create
expensive joins.

Is there any way to connect a group of fields to another virtual
relation?

ps. I tried has() and any() like with normal FKey.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread jason kirtland

Michael Bayer wrote:
 
 On Oct 13, 2008, at 10:58 AM, [EMAIL PROTECTED] wrote:
 
 On Monday 13 October 2008 17:21:31 Michael Bayer wrote:
 On Oct 13, 2008, at 6:41 AM, [EMAIL PROTECTED] wrote:
 why i cannot give in_() a bindparam?

 q.filter( x.in_( somelistorset )) works
 q.filter( x.in_( bindparam('somename') )) fails
 ...
 File sqlalchemy/sql/expression.py, line 1368, in _in_impl
for o in seq_or_selectable:
 TypeError: '_BindParamClause' object is not iterable

 is this possible or not ?
 or sending a list/tuple/iterable as bindparam-value is not
 supported?
 is this a resend?   I answered a week ago (hm, GG didnt
 deliver ?  )
 didnt...
 should be x.in_([bindparam('somename')])
 but that is a list containing one param.
 i want the whole list to be a parameter.
 
 
 yeah does PG even support that ?   im assuming PG

as ANY(array[])


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: similar to composite()

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 11:14 AM, g00fy wrote:


 I have my table Warehouse collumns like:
 id, owner_id  , area_total, area_office ... ,area_storage
 I would like to have acces to all areas by Warehouse.area.property:
 example:
 Warehouse.area.storage

 I did composite(), but now I can't filter like:
 filter(Warehouse.area.total =100) and even not by
 fitler(Warehouse.area_total =100)

 but i can access
 Warehouse.area.total

 I don't want to create aditional Area table, becouse that will create
 expensive joins.

 Is there any way to connect a group of fields to another virtual
 relation?


the functionality you describe is not built in to SQLA but you can  
roll it yourself by building your own proxy object, along the lines of:

class Warehouse(object):
 ...

class Proxy(object):
 def __getattr__(self, key):
 return getattr(Warehouse, key)

Warehouse.area = Proxy()

i wouldnt recommend composites since thats not a very well defined  
feature with SQLA, though that usage is interesting, perhaps somehting  
that can be implemented eventually.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] 0.4: can not append objects to instrumentedlists

2008-10-13 Thread _tyr_



I use entity_name's for all mappers. So I dont have mappers with
entity_name = None.

With sqlalchemy 0.4 I run into errors if I try to add objects to
InstrumentedList's:

(Pdb) len( self.users )
1
(Pdb) self.users
[common.User object at 0x1d1992a8]
(Pdb) type( self.users )
class 'sqlalchemy.orm.collections.InstrumentedList'
(Pdb)  self.users.append( user )
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/collections.py,
line 921, in append
item, _sa_initiator)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
517, in fire_append_event
ext.append(instance, value, initiator or self)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
713, in append
getattr(child.__class__, self.key).impl.append(child._state,
instance, initiator, passive=True)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
294, in append
self.set(state, value, initiator)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
437, in set
old = self.get(state)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
278, in get
callable_ = self._get_callable(state)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
255, in _get_callable
return self.callable_(state.obj())
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/strategies.py, line
318, in class_level_loader
localparent = mapper.object_mapper(instance)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/util.py, line 371,
in object_mapper
raise exceptions.InvalidRequestError(Class '%s' entity name '%s'
has no mapper associated with it % (object.__class__.__name__,
getattr(object, '_entity_name', entity_name)))
InvalidRequestError: Class 'User' entity name 'None' has no mapper
associated with it


It is a mistake on my part or a bug/broken feature (I migrate from
sqlalchemy 0.3 and it works with 0.3)?

thanks and greetings,
tyr

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

2008-10-13 Thread Michael Bayer

the entity_name feature is somewhat broken in 0.4 and has been removed  
entirely in 0.5 - there's too much ambiguity in its usage (namely, the  
attributes/behavior of a class cannot be determined until the class is  
associated with a specific mapper via the session).   Its possible  
that this is related to the issue you're having.

What is preventing you from simply mapping different classes ?




On Oct 13, 2008, at 11:31 AM, [EMAIL PROTECTED] wrote:




 I use entity_name's for all mappers. So I dont have mappers with
 entity_name = None.

 With sqlalchemy 0.4 I run into errors if I try to add objects to
 InstrumentedList's:

 (Pdb) len( self.users )
 1
 (Pdb) self.users
 [common.User object at 0x1d1992a8]
 (Pdb) type( self.users )
 class 'sqlalchemy.orm.collections.InstrumentedList'
 (Pdb)  self.users.append( user )
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/collections.py,
 line 921, in append
item, _sa_initiator)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 517, in fire_append_event
ext.append(instance, value, initiator or self)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 713, in append
getattr(child.__class__, self.key).impl.append(child._state,
 instance, initiator, passive=True)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 294, in append
self.set(state, value, initiator)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 437, in set
old = self.get(state)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 278, in get
callable_ = self._get_callable(state)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
 255, in _get_callable
return self.callable_(state.obj())
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/strategies.py, line
 318, in class_level_loader
localparent = mapper.object_mapper(instance)
  File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/util.py, line 371,
 in object_mapper
raise exceptions.InvalidRequestError(Class '%s' entity name '%s'
 has no mapper associated with it % (object.__class__.__name__,
 getattr(object, '_entity_name', entity_name)))
 InvalidRequestError: Class 'User' entity name 'None' has no mapper
 associated with it


 It is a mistake on my part or a bug/broken feature (I migrate from
 sqlalchemy 0.3 and it works with 0.3)?

 thanks and greetings,
 tyr

 


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: connect data base

2008-10-13 Thread Kyle Schaffrick

On Mon, 13 Oct 2008 01:53:13 -0700 (PDT)
nano [EMAIL PROTECTED] wrote:

 
 hello,
 I'm new to sqlalchemy and database
 I just installed postgres http://doc.fedora-fr.org/wiki/
 Installation_et_configuration_de_PostgreSQL,
 and I have a problem connecting to my database
 with a script sqlalchemy
 the error is 
 File/usr/lib/python2.4/site-packages/SQLAlchemy-0.4.0-
 py2.4.egg/sqlalchemy/engine/strategies.py, line 77, in connect raise
 exceptions.DBAPIError.instance(None, None, e)
 sqlalchemy.exceptions.OperationalError: (OperationalError) FATAL:
 Ident authentication failed for user postgres None None. Thanks.
 

This looks like either you forgot to put the username in your connection
string, or you have a PostgreSQL configuration problem.

It says you're trying to login with username postgres. However, on
most distributions postgres is the name of the DBMS's super-user
account, as well as the name of the POSIX account that PostgreSQL runs
as. Thus, for security reasons, by default you won't be able to log in
as postgres on the DBMS except from a local process running as the
POSIX account postgres. (Ident authentication just means your POSIX
account name must be the same as the DBMS account name)

Check that you have put a DBMS username and password in the connection
string of your engine, that the user has permission to access the
database you're trying to connect to, and that PG is configured to allow
that user to connect via TCP/IP using password authentication, not just
ident authentication.

Following the steps in the security and creating a user sections in
the wiki page you linked to should set up the user and permissions
properly. Whatever username/password you create with that procedure
should be the one you use for SQLAlchemy.

-Kyle

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: in_( bindparam(list) ) ?

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 10:58 AM, [EMAIL PROTECTED] wrote:


 On Monday 13 October 2008 17:21:31 Michael Bayer wrote:
 On Oct 13, 2008, at 6:41 AM, [EMAIL PROTECTED] wrote:
 why i cannot give in_() a bindparam?

 q.filter( x.in_( somelistorset )) works
 q.filter( x.in_( bindparam('somename') )) fails
 ...
 File sqlalchemy/sql/expression.py, line 1368, in _in_impl
for o in seq_or_selectable:
 TypeError: '_BindParamClause' object is not iterable

 is this possible or not ?
 or sending a list/tuple/iterable as bindparam-value is not
 supported?

 is this a resend?   I answered a week ago (hm, GG didnt
 deliver ?  )
 didnt...
 should be x.in_([bindparam('somename')])
 but that is a list containing one param.
 i want the whole list to be a parameter.


yeah does PG even support that ?   im assuming PG

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] in_( bindparam(list) ) ?

2008-10-13 Thread az

why i cannot give in_() a bindparam?   

q.filter( x.in_( somelistorset )) works
q.filter( x.in_( bindparam('somename') )) fails
...
File sqlalchemy/sql/expression.py, line 1368, in _in_impl
    for o in seq_or_selectable:
TypeError: '_BindParamClause' object is not iterable

is this possible or not ? 
or sending a list/tuple/iterable as bindparam-value is not supported?

ciao
svil

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Aw: [sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

2008-10-13 Thread _tyr_

 What is preventing you from simply mapping different classes ?
Different Customers uses different (her own) table spaces. So we must map a 
Class to different tables.

You remove entity_name, but how you specify the 'user dependent storage' in 
sqlalchem 0.5? This behavior is a typical orm-property. I know its a 
enterprise requirement. But it is the reason why I use sqlalchemy.

I spent some time to migrate to sqlalchemy 0.4 and it's to late to go back to 
0.3. What can I do to add objects to properties (InstumentedLists) in 
sqlalchemy 0.4 (with different mappers)?

Thanks
tyr





- Original Nachricht 
Von: Michael Bayer [EMAIL PROTECTED]
An:  sqlalchemy@googlegroups.com
Datum:   13.10.2008 17:42
Betreff: [sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

 
 the entity_name feature is somewhat broken in 0.4 and has been removed  
 entirely in 0.5 - there's too much ambiguity in its usage (namely, the  
 attributes/behavior of a class cannot be determined until the class is  
 associated with a specific mapper via the session).   Its possible  
 that this is related to the issue you're having.
 
 What is preventing you from simply mapping different classes ?
 
 
 
 
 On Oct 13, 2008, at 11:31 AM, [EMAIL PROTECTED] wrote:
 
 
 
 
  I use entity_name's for all mappers. So I dont have mappers with
  entity_name = None.
 
  With sqlalchemy 0.4 I run into errors if I try to add objects to
  InstrumentedList's:
 
  (Pdb) len( self.users )
  1
  (Pdb) self.users
  [common.User object at 0x1d1992a8]
  (Pdb) type( self.users )
  class 'sqlalchemy.orm.collections.InstrumentedList'
  (Pdb)  self.users.append( user )
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/collections.py,
  line 921, in append
 item, _sa_initiator)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  517, in fire_append_event
 ext.append(instance, value, initiator or self)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  713, in append
 getattr(child.__class__, self.key).impl.append(child._state,
  instance, initiator, passive=True)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  294, in append
 self.set(state, value, initiator)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  437, in set
 old = self.get(state)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  278, in get
 callable_ = self._get_callable(state)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/attributes.py, line
  255, in _get_callable
 return self.callable_(state.obj())
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/strategies.py, line
  318, in class_level_loader
 localparent = mapper.object_mapper(instance)
   File SQLAlchemy-0.4.8-py2.4.egg/sqlalchemy/orm/util.py, line 371,
  in object_mapper
 raise exceptions.InvalidRequestError(Class '%s' entity name '%s'
  has no mapper associated with it % (object.__class__.__name__,
  getattr(object, '_entity_name', entity_name)))
  InvalidRequestError: Class 'User' entity name 'None' has no mapper
  associated with it
 
 
  It is a mistake on my part or a bug/broken feature (I migrate from
  sqlalchemy 0.3 and it works with 0.3)?
 
  thanks and greetings,
  tyr
 
  
 
 
  
 

Jetzt komfortabel bei Arcor-Digital TV einsteigen: Mehr Happy Ends, mehr 
Herzschmerz, mehr Fernsehen! Erleben Sie 50 digitale TV Programme und optional 
60 Pay TV Sender, einen elektronischen Programmführer mit Movie Star 
Bewertungen von TV Movie. Außerdem, aktuelle Filmhits und spannende Dokus in 
der Arcor-Videothek. Infos unter www.arcor.de/tv

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Aw: [sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

2008-10-13 Thread jason kirtland

[EMAIL PROTECTED] wrote:
 
 I spent some time to migrate to sqlalchemy 0.4 and it's to late to go back to 
 0.3. What can I do to add objects to properties (InstumentedLists) in 
 sqlalchemy 0.4 (with different mappers)?

I suspect that case will work if you add the user to the session under 
the desired entity_name before appending to the collection.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: reflection unavailable for mysql temporary tables?

2008-10-13 Thread Andy Davidoff

On Oct 11, 1:29 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 11, 2008, at 12:49 PM, AndyDavidoffwrote:
  This fixes the first part of this problem, but unfortunately the `show
  create table` is performed in the connection, not the session in which
  the temporary table was created.  MySQL doesn't expose temporary
  tables between sessions, so the `show create table` raises a MySQL
  exception due to a non-existent table.

 you can reflect any table on a specific connection using  
 autoload_with=someconnection.  if by Session you mean ORM session,  
 get the current connection using session.connection().

Thanks, but MySQL's temporary tables are invisible to connection
objects; the reflection would need to occur via queries issued in the
actual Session (ORM session) in which the tables were created.  I
doubt this'll be easy to elegantly hack into SQLA, though.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Passing a param that is a list to execute()

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 11:13 AM, Jonathan Marshall wrote:


 Hi,

 I'm not sure whether this is a bug in sqlalchemy or user error. I'm
 having trouble passing a parameter to execute() that is a list of
 values for the in operator.

 E.g.:
  session.execute(sql.text('SELECT * from users where x in :xs'),
 params={'xs' : some_seq})

 This works fine when using MySQL so long as some_seq is a list of
 integers. It does not return the correct results if some_seq is a list
 of strings. It always fails with OperationalError when using sqlite.

 The in_ operator works correctly however my application needs to
 support text SQL input.


this is exactly like az's post.   My own possibly naive understanding  
of IN is that it needs to be rendered with individual parameters, i.e.  
IN (?, ?, ?, ?).   I was never aware of the ability to use IN with a  
single array-holding bind parameter.   I haven't experimented with  
this so I could be completely off.



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: reflection unavailable for mysql temporary tables?

2008-10-13 Thread jason kirtland

Andy Davidoff wrote:
 On Oct 11, 1:29 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 11, 2008, at 12:49 PM, AndyDavidoffwrote:
 This fixes the first part of this problem, but unfortunately the `show
 create table` is performed in the connection, not the session in which
 the temporary table was created.  MySQL doesn't expose temporary
 tables between sessions, so the `show create table` raises a MySQL
 exception due to a non-existent table.
 you can reflect any table on a specific connection using  
 autoload_with=someconnection.  if by Session you mean ORM session,  
 get the current connection using session.connection().
 
 Thanks, but MySQL's temporary tables are invisible to connection
 objects; the reflection would need to occur via queries issued in the
 actual Session (ORM session) in which the tables were created.  I
 doubt this'll be easy to elegantly hack into SQLA, though.

No hacking needed, it works just as Mike described.

from sqlalchemy import *
from sqlalchemy.orm import create_session

session = create_session()
session.bind = create_engine('mysql:///test')

session.begin()

session.execute('CREATE TEMPORARY TABLE foo (x INT)')
session.execute('INSERT INTO foo VALUES (1)')

m = MetaData()
tt = Table('foo', m, autoload=True, autoload_with=session.connection())
print session.execute(tt.select()).fetchall()

session.commit()


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: similar to composite()

2008-10-13 Thread az

see a thread composites started by me on 21.08.2008 - i have 
something named composer for such embedded structures but i have 
not yet moved further into how to make that one a Comparable in terms 
of query.filter(). u can try do it...

On Monday 13 October 2008 18:14:42 g00fy wrote:
 I have my table Warehouse collumns like:
 id, owner_id  , area_total, area_office ... ,area_storage
 I would like to have acces to all areas by Warehouse.area.property:
 example:
 Warehouse.area.storage

 I did composite(), but now I can't filter like:
 filter(Warehouse.area.total =100) and even not by
 fitler(Warehouse.area_total =100)

 but i can access
 Warehouse.area.total

 I don't want to create aditional Area table, becouse that will
 create expensive joins.

 Is there any way to connect a group of fields to another virtual
 relation?

 ps. I tried has() and any() like with normal FKey.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Aw: [sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 12:22 PM, [EMAIL PROTECTED] wrote:


 What is preventing you from simply mapping different classes ?
 Different Customers uses different (her own) table spaces. So we  
 must map a Class to different tables.

 You remove entity_name, but how you specify the 'user dependent  
 storage' in sqlalchem 0.5? This behavior is a typical orm-property.  
 I know its a enterprise requirement. But it is the reason why I  
 use sqlalchemy.

It's specifically a Hibernate/Java ORM requirement, because in Java,  
subclasses are not cheap.  The reality is, by using entity_name, you  
associate an entity_name attribute with your instance after it's  
added to the Session, which then determines behavior of that  
instance.  Before its added, there is no entity_name, and behavior  
is undefined.  In Hibernate, the ORM defines much less behavior on  
classes since you are required to spell out all instance members and  
collections explicitly.   Hibernate also does not place any behavior  
upon non-instantiated classes; most Python ORMs like SQLAlchemy do,  
i.e. you can say Customer.name=='ed'.  0.5 relies much more heavily  
on class behavior in terms of querying than previous versions.  As you  
can see here:  
http://www.hibernate.org/hib_docs/v3/reference/en/html/persistent-classes-dynamicmodels.html
 
  , Hibernate uses entity_name to add dynamic class behavior to  
Java, something the language otherwise does not have.  Python is  
already a dynamic language so there's many ways to solve the problem  
that entity_name does in Hibernate.

Because of the way SQLA adds behavior to instances, through  
instrumentation, the only way entity_name can ever work in a solid,  
enterprise sense of the word is if it is specified upon instance  
creation, i.e. MyInstance(foo, bar, entity_name='foo').   Class  
behavior is also not possible at all and special wrappers are needed  
to achieve SQLA's class level behavior, i.e. SomeClass =  
myentity(MyClass, 'foo'); SomeClass.name == 'ed' (additionally, any  
number of classes can be sent to session.query() now, so theres no  
place for an entity_name keyword argument in any case).   There is  
really no abstraction of entity from mapped instance here - they  
need to be stated together.

With that restriction in mind, you can get similar behavior without an  
entity_name feature at all:

class Customer(object):
def __new__(cls, entity_name, *args, **kw):
if entity_name == 'ed':
return object.__new__(EdCustomer)
elif entity_name == 'wendy':
return object.__new__(WendyCustomer)
else:
raise Exception(unknown entity %s % 
entity_name)

querying looks like:

sess.query(WendyCustomer).filter(WendyCustomer.some_number==12)

an equivent function to mapper() with entity_name which creates types  
dynamically (and also stores them in a dict):

mappers = {}
def entity_mapper(basecls, table, entity_name, **kwargs):
cls = type.__new__(type, %s%s % (entity_name, 
basecls.__name__),  
(basecls,), {})
m = mapper(cls, table, **kwargs)
mappers[(basecls, entity_name)] = m
return cls

If you've built entity_mapper, we can rewrite Customer to use the  
mappers as a guide:

def entity_named(cls, entity_name):
try:
return mappers[(cls, entity_name)].class_
except KeyError:
raise Exception(unknown entity %s % entity_name)

class Customer(object):
def __new__(cls, entity_name, *args, **kw):
return object.__new__(entity_named(cls, entity_name))

So the equivalent of:

c = Customer()
sess.save(c, entity_name='foo')

becomes:

c = Customer(entity_name='foo')
sess.save(c)

the equivalent of:

sess.query(Customer,  
entity_name=foo).filter(customer_table.c.name=='ed')

becomes:

EdCustomer = entity_named(Customer, foo)
sess.query(EdCustomer).filter(EdCustomer.name=='ed')...

Theres many ways to roll behavior like the above, these are just some  
ideas.The main idea is that entity_name isn't adding any value  
that you can't create more effectively on your own.

For more background, I wrote about this here:  
http://groups.google.com/group/sqlalchemy/browse_thread/thread/9e23a0641a88b96d/391326fcf89c05d4?lnk=gstq=entity_name#391326fcf89c05d4
 
  .

As far as the specfic issue you're having, it does seem like an 0.4  
bug - its consulting the lazy loader for the instance when none should  
be consulted at all, if the object is only transient.  So Jek's  
suggestion of placing the object in the session before accessing the  
collection is a good bet for 0.4.



--~--~-~--~~~---~--~~
You 

[sqlalchemy] Re: reflection unavailable for mysql temporary tables?

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 12:29 PM, Andy Davidoff wrote:


 On Oct 11, 1:29 pm, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 11, 2008, at 12:49 PM, AndyDavidoffwrote:
 This fixes the first part of this problem, but unfortunately the  
 `show
 create table` is performed in the connection, not the session in  
 which
 the temporary table was created.  MySQL doesn't expose temporary
 tables between sessions, so the `show create table` raises a MySQL
 exception due to a non-existent table.

 you can reflect any table on a specific connection using
 autoload_with=someconnection.  if by Session you mean ORM  
 session,
 get the current connection using session.connection().

 Thanks, but MySQL's temporary tables are invisible to connection
 objects; the reflection would need to occur via queries issued in the
 actual Session (ORM session) in which the tables were created.  I
 doubt this'll be easy to elegantly hack into SQLA, though.

I mean this:

sess = sessionmaker(autocommit=False)
sess.execute(do something that creates a temporary table)
my_temporary_table = Table(my_temporary_table, MetaData(),  
autoload=True, autoload_with=sess.connection())

i.e., use the Connection object referenced by the Session.  as long as  
you are autocommit=False it will persist until you say commit() or  
rollback().


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: similar to composite()

2008-10-13 Thread g00fy

How this Proxy object is going to work exacly?
Will that generate extra Sql or what?
I assume that I should just change __getattr__() to desired and return
Warehouse.key ? or warehouse_table.c.key?

On 13 Paź, 17:25, Michael Bayer [EMAIL PROTECTED] wrote:
 On Oct 13, 2008, at 11:14 AM, g00fy wrote:





  I have my table Warehouse collumns like:
  id, owner_id  , area_total, area_office ... ,area_storage
  I would like to have acces to all areas by Warehouse.area.property:
  example:
  Warehouse.area.storage

  I did composite(), but now I can't filter like:
  filter(Warehouse.area.total =100) and even not by
  fitler(Warehouse.area_total =100)

  but i can access
  Warehouse.area.total

  I don't want to create aditional Area table, becouse that will create
  expensive joins.

  Is there any way to connect a group of fields to another virtual
  relation?

 the functionality you describe is not built in to SQLA but you can  
 roll it yourself by building your own proxy object, along the lines of:

 class Warehouse(object):
      ...

 class Proxy(object):
      def __getattr__(self, key):
          return getattr(Warehouse, key)

 Warehouse.area = Proxy()

 i wouldnt recommend composites since thats not a very well defined  
 feature with SQLA, though that usage is interesting, perhaps somehting  
 that can be implemented eventually.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] How to pass null values

2008-10-13 Thread Mike

Hi,

I am trying to transfer some data from a sqlite database to an MS SQL
database. I need to be able to pass null values for some of the empty
columns in the row. For example, I have something like this for my
row's format:

date | id | reg | ot | hol

The first two fields are required, but any or all of the last three
can be null. How do I tell SqlAlchemy that I want those to be null?
I've tried using None, an empty string, and the string
DEFAULT (which works for pymssql for whatever reason).

My class instantiation would look like this:

TimeEntries(data, id, reg, ot, hol, *args)

I am using the 0.5.0rc1 version of SqlAlchemy with Python 2.5.2 on
Windows XP. Any hints would be appreciated.

Thanks,

Mike
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: How to pass null values

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 2:59 PM, Mike wrote:


 Hi,

 I am trying to transfer some data from a sqlite database to an MS SQL
 database. I need to be able to pass null values for some of the empty
 columns in the row. For example, I have something like this for my
 row's format:

 date | id | reg | ot | hol

 The first two fields are required, but any or all of the last three
 can be null. How do I tell SqlAlchemy that I want those to be null?
 I've tried using None, an empty string, and the string
 DEFAULT (which works for pymssql for whatever reason).

 My class instantiation would look like this:

 TimeEntries(data, id, reg, ot, hol, *args)

 I am using the 0.5.0rc1 version of SqlAlchemy with Python 2.5.2 on
 Windows XP. Any hints would be appreciated.


None or leave the paramter out of the INSERT entirely will work.  Not  
sure about specific quirks in MS-SQL drivers though as far as your  
attempt of None not working, are you using pyodbc at least ?



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: similar to composite()

2008-10-13 Thread Michael Bayer


On Oct 13, 2008, at 2:50 PM, g00fy wrote:


 How this Proxy object is going to work exacly?
 Will that generate extra Sql or what?
 I assume that I should just change __getattr__() to desired and return
 Warehouse.key ? or warehouse_table.c.key?


the proxy, which actually should read:

class Proxy(object):
 def __getattr__(self, key):
 return getattr(Warehouse, area_ + key)

works only at the class level and translates someting like  
Warehouse.area.office into Warehouse.area_office.   It's merely a  
Python trick to change how you access a particular class-level  
attribute.

SQLA 0.4 and above prefer class-level attributes to create expression  
predicates.   The ORM tutorials for 0.4 and 0.5 cover this in depth.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Aw: [sqlalchemy] Re: Aw: [sqlalchemy] Re: 0.4: can not append objects to instrumentedlists

2008-10-13 Thread _tyr_

many thanks to jason and michael!

I add the objects to the current session and ... it works.

Migration to 0.5 seems to be a big step (for us). 
We don't use fancy orm tricks. The only thing are 'user dependet table spaces'. 
Hence its possible your example, michael, can work for us. Thanks.

greetings,
tyr 


- Original Nachricht 
Von: Michael Bayer [EMAIL PROTECTED]
An:  sqlalchemy@googlegroups.com
Datum:   13.10.2008 19:51
Betreff: [sqlalchemy] Re: Aw: [sqlalchemy] Re: 0.4: can not append objects to
 instrumentedlists

 
 
 On Oct 13, 2008, at 12:22 PM, [EMAIL PROTECTED] wrote:
 
 
  What is preventing you from simply mapping different classes ?
  Different Customers uses different (her own) table spaces. So we  
  must map a Class to different tables.
 
  You remove entity_name, but how you specify the 'user dependent  
  storage' in sqlalchem 0.5? This behavior is a typical orm-property.  
  I know its a enterprise requirement. But it is the reason why I  
  use sqlalchemy.
 
 It's specifically a Hibernate/Java ORM requirement, because in Java,  
 subclasses are not cheap.  The reality is, by using entity_name, you  
 associate an entity_name attribute with your instance after it's  
 added to the Session, which then determines behavior of that  
 instance.  Before its added, there is no entity_name, and behavior  
 is undefined.  In Hibernate, the ORM defines much less behavior on  
 classes since you are required to spell out all instance members and  
 collections explicitly.   Hibernate also does not place any behavior  
 upon non-instantiated classes; most Python ORMs like SQLAlchemy do,  
 i.e. you can say Customer.name=='ed'.  0.5 relies much more heavily  
 on class behavior in terms of querying than previous versions.  As you  
 can see here: 
 http://www.hibernate.org/hib_docs/v3/reference/en/html/persistent-classes-dy
 namicmodels.html 
   , Hibernate uses entity_name to add dynamic class behavior to  
 Java, something the language otherwise does not have.  Python is  
 already a dynamic language so there's many ways to solve the problem  
 that entity_name does in Hibernate.
 
 Because of the way SQLA adds behavior to instances, through  
 instrumentation, the only way entity_name can ever work in a solid,  
 enterprise sense of the word is if it is specified upon instance  
 creation, i.e. MyInstance(foo, bar, entity_name='foo').   Class  
 behavior is also not possible at all and special wrappers are needed  
 to achieve SQLA's class level behavior, i.e. SomeClass =  
 myentity(MyClass, 'foo'); SomeClass.name == 'ed' (additionally, any  
 number of classes can be sent to session.query() now, so theres no  
 place for an entity_name keyword argument in any case).   There is  
 really no abstraction of entity from mapped instance here - they  
 need to be stated together.
 
 With that restriction in mind, you can get similar behavior without an  
 entity_name feature at all:
 
   class Customer(object):
   def __new__(cls, entity_name, *args, **kw):
   if entity_name == 'ed':
   return object.__new__(EdCustomer)
   elif entity_name == 'wendy':
   return object.__new__(WendyCustomer)
   else:
   raise Exception(unknown entity %s % 
 entity_name)
 
 querying looks like:
 
   sess.query(WendyCustomer).filter(WendyCustomer.some_number==12)
 
 an equivent function to mapper() with entity_name which creates types  
 dynamically (and also stores them in a dict):
 
   mappers = {}
   def entity_mapper(basecls, table, entity_name, **kwargs):
   cls = type.__new__(type, %s%s % (entity_name, 
 basecls.__name__),  
 (basecls,), {})
   m = mapper(cls, table, **kwargs)
   mappers[(basecls, entity_name)] = m
   return cls
 
 If you've built entity_mapper, we can rewrite Customer to use the  
 mappers as a guide:
 
   def entity_named(cls, entity_name):
   try:
   return mappers[(cls, entity_name)].class_
   except KeyError:
   raise Exception(unknown entity %s % entity_name)
 
   class Customer(object):
   def __new__(cls, entity_name, *args, **kw):
   return object.__new__(entity_named(cls, entity_name))
 
 So the equivalent of:
 
   c = Customer()
   sess.save(c, entity_name='foo')
 
 becomes:
 
   c = Customer(entity_name='foo')
   sess.save(c)
 
 the equivalent of:
 
   sess.query(Customer,  
 entity_name=foo).filter(customer_table.c.name=='ed')
 
 becomes:
 
   EdCustomer = entity_named(Customer, foo)
   sess.query(EdCustomer).filter(EdCustomer.name=='ed')...
 
 Theres many ways to roll behavior like the above, these are just some  
 ideas.The main idea is that entity_name isn't adding any value  
 that you can't create more