Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
5958 Widoki

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.


Awatar
Odrzuć
Najlepsza odpowiedź

You found a solution ?

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
6
gru 23
66249
1
mar 19
10662
0
lut 16
4
0
gru 15
3630
2
mar 15
10413