콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

I have sql constraint defined like this:

_sql_constraints = [
     ('checksum_uniq', 'unique(checksum)', ' The same file already exists in the system!'),
     ]

Then in a loop I create records

for file in files:
    try:
        self.env[model].create({'filename':file.fname,'file':file.file_data})
    except IntegrityError, e:
print 'skipping file ' + file.fname

The problem is that the cursor is closed after IntegrityError so the loop fails after that but I want to skip the records that fail and continue the loop.


아바타
취소
베스트 답변

You found a solution ?

아바타
취소
베스트 답변

how to continue for loop when create has error? 
use continue and pass do not work. 

아바타
취소
베스트 답변

for file in files:
    if file:
        self.env[model].create({'filename':file.fname,'file':file.file_data})
    else:
print 'skipping file ' + file.fname

아바타
취소
작성자

This doesn't really makes sense. Maybe I was not clear but the problem is that if file.checksum is duplicated with another already in the system then it throws a Error and the only option I have is to rollback the whole transaction

관련 게시물 답글 화면 활동
6
12월 23
66231
1
3월 19
10654
0
2월 16
4
0
12월 15
3624
2
3월 15
10398