There are some problem with this although they are not the case of your
traceback.
- One problem is hat this allows any visitor to delete any record in any
table. But you know that.
- The second problem is that you deleted the record you are editing on
validation, before it gets updated. When web2py calls update_record the
record has been deleted. I do not think the exception happens where you
catch it. It happens later when update_record is called.
Can you explain us what is the purpose of this code?
On Tuesday, 11 December 2012 15:50:25 UTC-6, Richard wrote:
>
> Do I am doing right?
>
> def ondelete_func(form):
> """try delete ondelete if database raise an error trigger a message
> telling the user that the record can't be deleted"""
> import psycopg2
> try:
> db(db[request.args(0)].id==request.args(1)).delete()
> except psycopg2.IntegrityError:
> db.rollback()
> session.flash = T('The record you try to delete is still
> referenced by other records and can\'t be deleted')
>
> def create_update():
> """create update funciton"""
> form = crud.update(db[request.args(0)], request.args(1),
> onvalidation=ondelete_func)
> return dict(form=form)
>
> I still get this ticket :
>
> <class 'psycopg2.IntegrityError'> ERREUR: UPDATE ou DELETE sur la table «
> table2 » viole la contrainte de clé étrangère « fk_table3 » de la table «
> table3 » DETAIL: La clé (id)=(2) est toujours référencée à partir de la
> table « table3 »
>
>
> And I am not sure how I can revert the crud.update deletion the way I code
> that.
>
> Thanks
>
> Richard
>
> On Tue, Dec 11, 2012 at 4:45 PM, Richard Vézina
> <[email protected]<javascript:>
> > wrote:
>
>> So, it may be the reason I get internal error then. And the Niphold code
>> is working. I make test.
>>
>> Richard
>>
>>
>> On Tue, Dec 11, 2012 at 4:40 PM, Massimo Di Pierro
>> <[email protected]<javascript:>
>> > wrote:
>>
>>> Mand that you if catch a DB exception you must revert or you cannot do
>>> anything else with the DB within the transaction and you end up with a
>>> ticket.
>>>
>>>
>>> On Tuesday, 11 December 2012 14:52:08 UTC-6, Richard wrote:
>>>
>>>> I have to see if record of table2 is attached by table3 in my example,
>>>> but in my app actually, table3 is 30 differents tables that each can refer
>>>> to table2 entry multiple time (one to many)...
>>>>
>>>> I would prefer to do what you suggest "child tables" but I am afraid of
>>>> overhead.
>>>>
>>>> Richard
>>>>
>>>>
>>>> On Tue, Dec 11, 2012 at 3:32 PM, Niphlod <[email protected]> wrote:
>>>>
>>>>> ere are records attached.
>>>>
>>>>
>>>> --
>>>
>>>
>>>
>>>
>>
>>
>
--