Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
5949 มุมมอง

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
6
ธ.ค. 23
66236
1
มี.ค. 19
10657
0
ก.พ. 16
4
0
ธ.ค. 15
3626
2
มี.ค. 15
10401