Hi,

I followed the guidelines provided into this post to hook in my custom
ID generator. - 
http://article.gmane.org/gmane.comp.python.sqlalchemy.user/3236/match=id+generator
However it does not get invoked upon each insert and hence gives me an
integrity error at runtime.

def get_next_id():
    session = meta.Session()
    query = session.query(PKGenerator).filter_by
(table_name='principals')
    nxpkgen = query.first()
    if nxpkgen:
        nxid = nxpkgen.next_id
        if nxid > nxpkgen.end_id:
            raise Exception('Primary Key range has been exhausted')
        nxpkgen.next_id += 1
        session .commit()
        return nxid
    else:
        raise Exception('Next Primary Key could not be found')

My entity's PK Column definition looks like this.
    id = Column(bigint,Sequence('principals_seq_id',optional=True),
 
primary_key=True,autoincrement=False,default=generator.get_next_id())


When I run my app, i get these
12:18:18,078 INFO  [sqlalchemy.engine.base.Engine.0x...be0c][945]
INSERT INTO principals (id, handle, name, type, subtype, created_on,
last_updated) VALUES (%s, %s, %s, %s, %s, CURRENT_TIMESTAMP, %s)
12:18:18,078 INFO  [sqlalchemy.engine.base.Engine.0x...be0c][946]
[12L, u'rpithadiya', 'Ritesh Pithadiya', 'user', u'user', None]
12:18:18,079 INFO  [sqlalchemy.engine.base.Engine.0x...be0c][945]
INSERT INTO principals (id, handle, name, type, subtype, created_on,
last_updated) VALUES (%s, %s, %s, %s, %s, CURRENT_TIMESTAMP, %s)
12:18:18,079 INFO  [sqlalchemy.engine.base.Engine.0x...be0c][946]
[12L, u'hdfcbank', 'HDFC Bank Ltd.', 'enterprise', u'bank', None]
12:18:18,080 INFO  [sqlalchemy.engine.base.Engine.0x...be0c][733]
ROLLBACK
12:18:18,085 DEBUG [pluto.controllers.enterpriseusers][71] Problems
creating enterprise users - (IntegrityError) (1062, "Duplicate entry
'12' for key 1")

Please advise if I am missing something here.

Regards,
Naresh

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

Reply via email to