On 13 April 2012 21:46, Richard Vézina <[email protected]> wrote:
> This solution look great, because until now web2py was triggering a error
> if postgres return not unique and won't insert the data...
>
>
This problem has bitten me again. My previous test was in the console.
Now in a controller I did the following:
def koppel_skrywer_artikel():
response.view = 'default/edit_journal.html'
opskrif = CENTER(H2(T('Add link between author and article')))
form=SQLFORM.factory(db.akb_authors_article_link)
if form.process().accepted:
try:
db.akb_authors_article_link.insert(**form.vars)
response.flash = T('Link inserted in database')
db.commit()
else:
response.flash = T('Link already in table')
return locals()
Which resulted in the following ticket (which shows that the 'try.. except'
was practically ignored.
File "/home/js/web2py/applications/init/controllers/default.py"
<http://localhost:8000/admin/default/edit/init/controllers/default.py>,
line 1206, in koppel_skrywer_artikel
form = crud.create(db.akb_authors_article_link)
File "/home/js/web2py/gluon/tools.py", line 3285, in create
formname=formname,
File "/home/js/web2py/gluon/tools.py", line 3228, in update
detect_record_change = self.settings.detect_record_change):
File "/home/js/web2py/gluon/sqlhtml.py", line 1296, in accepts
self.vars.id = self.table.insert(**fields)
File "/home/js/web2py/gluon/dal.py", line 7221, in insert
ret = self._db._adapter.insert(self,self._listify(fields))
File "/home/js/web2py/gluon/dal.py", line 991, in insert
raise e
IntegrityError: duplicate key value violates unique constraint "art_auth"
DETAIL: Key (author, article)=(ebff17aa-3d19-4580-bf4e-9580e99b6e0d,
6e9cc285-543c-4a59-aa52-f3bfbeb939ee) already exists.
Is there any chance that we can get DAL to play with this code?
Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you. (Psalm 63:3)