While writing a quick TG2 app, I ran into an error while doing a
redirect:
KeyError: 'ticket_id'
The code in question is:
@expose('cp.templates.template')
def ticketupdate(self, **kw):
ticket_id = kw['ticket_id']
provider.add('cp_ticket_detail', values=kw)
provider.edit('cp_ticket',values=kw)
redirect('/tech/ticket/%d' % kw['ticket_id']);
both the add and edit run properly, however, if I alter the code to:
@expose('cp.templates.template')
def ticketupdate(self, **kw):
ticket_id = kw['ticket_id']
provider.add('cp_ticket_detail', values=kw)
print kw
provider.edit('cp_ticket',values=kw)
print kw
redirect('/tech/ticket/%d' % kw['ticket_id']);
I get the following in the debug log:
10:52:32,237 INFO [sqlalchemy.engine.base.Engine.0x...b28c] INSERT
INTO cp_ticket_detail (ticket_id, detail) VALUES (%s, %s)
10:52:32,238 INFO [sqlalchemy.engine.base.Engine.0x...b28c] [u'4008',
u'asdfasfasf']
10:52:32,239 INFO [sqlalchemy.engine.base.Engine.0x...b28c] COMMIT
{'status': u'P', 'detail': u'asdfasfasf', 'submit': u'UPDATE TICKET
INFO', 'ticket_id': u'4008'}
10:52:32,240 INFO [sqlalchemy.engine.base.Engine.0x...b28c] UPDATE
cp_ticket SET status=%s WHERE cp_ticket.ticket_id = %s
10:52:32,240 INFO [sqlalchemy.engine.base.Engine.0x...b28c] [u'P',
u'4008']
10:52:32,241 INFO [sqlalchemy.engine.base.Engine.0x...b28c] COMMIT
{'status': u'P', 'detail': u'asdfasfasf', 'submit': u'UPDATE TICKET
INFO'}
If we look at the contents of kw prior to the update, ticket_id is
present. After the update, ticket_id is gone.
ticket_id is a primary key on cp_ticket and it does properly update
the ticket.
I've worked around it by saving kw['ticket_id'] ahead of time, but, is
this a bug or intended behavior?
Debian Linux 3.0/testing
python 2.5.4
TurboGears2-2.0-py2.5.egg
DBSprockets-0.5dev_r417-py2.5.egg
SQLAlchemy-0.5.1-py2.5.egg
models:
class cp_ticket(DeclarativeBase):
__tablename__ = 'cp_ticket'
ticket_id = Column(mysql.MSBigInteger(20, unsigned = True),
primary_key=True, autoincrement = True)
client_id = Column(mysql.MSBigInteger(20, unsigned = True),
ForeignKey('clients.client_id'), default = '1')
stamp = Column(mysql.MSDateTime, default = '1')
last_alert = Column(mysql.MSTimeStamp, default = '1')
tech_id = Column(mysql.MSTinyInteger(4, unsigned = True), default
= '1')
subject = Column(Unicode(100), default = 'Trouble Report from
CCM')
status = Column(mysql.MSEnum('U','A','P','C','R','S'), default =
'U')
priority = Column(mysql.MSEnum('1','2','3','4','5'), default =
'3')
domain = Column(Unicode(80))
clients = relation(clients, backref=backref('clients',
order_by=client_id))
class cp_ticket_detail(DeclarativeBase):
__tablename__ = 'cp_ticket_detail'
ticket_id = Column(mysql.MSBigInteger(20, unsigned = True),
ForeignKey('cp_ticket.ticket_id'), default = '0')
ticket_detail_id = Column(mysql.MSBigInteger(20, unsigned = True),
primary_key=True, autoincrement = True)
stamp = Column(mysql.MSTimeStamp, PassiveDefault
('CURRENT_TIMESTAMP'))
detail = Column(mysql.MSLongText, default = '0')
ticket = relation(cp_ticket, backref=backref
('cp_ticket_detail',order_by=ticket_detail_id))
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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/turbogears-trunk?hl=en
-~----------~----~----~----~------~----~------~--~---