Project

General

Profile

« Previous | Next » 

Revision 3352

sql_io.py: put_table(): Handle CheckExceptions. This fixes a REMIB bug where some rows violated the specimenreplicate.specimenreplicate_required_key CHECK constraint, but there was previously no way to filter out just these rows so all rows were removed instead.

View differences:

sql_io.py
317 317
    insert_in_table = in_table
318 318
    insert_in_tables = [insert_in_table]
319 319
    conds = set()
320
    join_cols = sql_gen.ColDict(db, out_table)
320 321
    distinct_on = sql_gen.ColDict(db, out_table)
321 322
    def mk_main_select(joins, cols):
322 323
        conds_ = [(sql_gen.with_table(k, insert_in_table), v) for k, v in conds]
......
334 335
        log_debug('Ignoring all rows')
335 336
        limit_ref[0] = 0 # just create an empty pkeys table
336 337
    
338
    def ignore_cond(cond, e):
339
        out_table_cols = sql_gen.ColDict(db, out_table)
340
        out_table_cols.update(util.dict_subset_right_join({},
341
            sql.table_cols(db, out_table)))
342
        
343
        in_cols = []
344
        cond = sql.map_expr(db, cond, mapping, in_cols)
345
        cond = sql.map_expr(db, cond, out_table_cols)
346
        
347
        track_data_error(db, errors_table_, sql_gen.cols_srcs(in_cols), None,
348
            e.cause.pgcode,
349
            strings.ensure_newl(e.cause.pgerror)+'condition: '+cond)
350
        
351
        not_cond = sql_gen.NotCond(sql_gen.CustomCode(cond))
352
        log_debug('Ignoring rows where '+strings.as_tt(not_cond.to_str(db)))
353
        sql.delete(db, insert_in_table, not_cond)
354
    
337 355
    not_null_cols = set()
338 356
    def ignore(in_col, value, e):
339 357
        in_col = sql_gen.with_table(in_col, insert_in_table)
......
359 377
    insert_in_pkeys = insert_pkeys_table('in')
360 378
    
361 379
    # Do inserts and selects
362
    join_cols = sql_gen.ColDict(db, out_table)
363 380
    while True:
364 381
        if limit_ref[0] == 0: # special case
365 382
            log_debug('Creating an empty pkeys table')
......
442 459
                if default == None: on_error(SyntaxError(msg)) # required col
443 460
                remove_all_rows()
444 461
            else: ignore(in_col, None, e)
462
        except sql.CheckException, e:
463
            log_exc(e)
464
            
465
            ignore_cond(e.cond, e)
445 466
        except sql.DatabaseErrors, e:
446 467
            log_exc(e)
447 468
            

Also available in: Unified diff