Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
3 Antworten
5953 Ansichten

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.


Avatar
Verwerfen
Beste Antwort

You found a solution ?

Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
Beste Antwort

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

Avatar
Verwerfen
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

Verknüpfte Beiträge Antworten Ansichten Aktivität
6
Dez. 23
66243
1
März 19
10660
0
Feb. 16
4
0
Dez. 15
3628
2
März 15
10411