thats a bug, i fixed it in r2291.

if you dont want to use the trunk for now, you can probably define  
the column as:

Column('obj_id', integer, default=func.obj_id_seq.nextval())


On Feb 2, 2007, at 4:05 AM, che wrote:

>
> Hi,
> I have a table with column that must use sequence generated number
> (for example in Postgres), like this obj_id:
>     table_Manager = Table( 'Manager', meta,
>         Column( 'obj_id', Integer, Sequence('obj_id_seq'), ),
>         Column( 'duties', type= String, ),
>         Column( 'name', type= String, ),
>         Column( 'id', Integer, primary_key= True, ),
>     )
> You see obj_id is not the primary key of the column.
> What i get as a result that SA correctly gets number from its
> obj_id_seq, logs shows that it even tries to insert it to the
> database, but in the end it remains Null (in the DB).
> Is it this my mistake or is this possible at all?
> TIA
> Stefan
>
> the code below demonstrates the issue:
> ----------------------------------
> from sqlalchemy import *
>
> import os
> try:
>     r = os.system( 'dropdb proba')
>     r = os.system( 'createdb proba')
> except OSError: pass
> db_postgres = create_engine( 'postgres://[EMAIL PROTECTED]:5432/proba')
> assert not 'FIX USERNAME in the above line and than remove me!!!'
>
> def checkWith( db):
>     meta = BoundMetaData( db)
>     meta.engine.echo = 1
>
>     table_Manager = Table( 'Manager', meta,
>         Column( 'obj_id', Integer, Sequence('obj_id_seq'), ),
>         Column( 'duties', type= String, ),
>         Column( 'name', type= String, ),
>         Column( 'id', Integer, primary_key= True, ),
>     )
>
>     class Manager( object):
>         def set( me, **kargs):
>             for k,v in kargs.iteritems(): setattr( me, k, v)
>             return me
>         def __str__(me): return str(me.__class__.__name__)
> +':'+str(me.name)
>         __repr__ = __str__
>
>     meta.create_all()
>     mapper_Manager = mapper( Manager, table_Manager)
>     import datetime
>
>     c = Manager().set( name= 'pencho', duties= 'many')
>
>     session = create_session()
>     session.save(c)
>     session.flush()
>
>     print c
>     print session.query( Manager).select()
>
>     d = Manager().set( name= 'torencho', duties= 'bany')
>     e = Manager().set( name= 'mnogoVojdMalkoIndianec', duties= 'lany')
>
>     session = create_session()
>     session.save(d)
>     session.save(e)
>     session.flush()
>     print '\n\nobjID in objects:', c.obj_id, d.obj_id, e.obj_id
>
>     res = session.query( Manager).select()
>     print '\nBEFORE session close'
>     for i in res:
>         print 'OBJ( Id: %s Obj_id: %s)' % (i.id, i.obj_id)
>     session.close()
>     session = create_session()
>     res = session.query( Manager).select()
>     print '\nAFTER session close'
>     for i in res:
>         print 'OBJ( Id: %s Obj_id: %s)' % (i.id, i.obj_id)
>
>
> checkWith( db_postgres)
> --------------------------------------------------
> After session close Obj_id is None.
>
>
> >


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

Reply via email to