Project

General

Profile

« Previous | Next » 

Revision 2429

sql.py: put_table(): Handle unknown exceptions by returning NULL for all rows. Refactored Missing mapping for NOT NULL column handling to use new helper function remove_all_rows().

View differences:

sql.py
880 880
            run_query_into(db, query, params, into=pkeys)
881 881
            pkeys_table_exists_ref[0] = True
882 882
    
883
    limit = None
883
    limit_ref = [None]
884 884
    conds = set()
885 885
    distinct_on = []
886 886
    def mk_main_select(joins, cols):
887
        return mk_select(db, joins, cols, conds, distinct_on, limit=limit,
888
            start=0)
887
        return mk_select(db, joins, cols, conds, distinct_on,
888
            limit=limit_ref[0], start=0)
889 889
    
890 890
    def log_exc(e):
891 891
        db.log_debug('Caught exception: '+exc.str_(e, first_line_only=True))
892
    def remove_all_rows(msg):
893
        warnings.warn(DbWarning(msg))
894
        db.log_debug(msg.partition('\n')[0])
895
        db.log_debug('Returning NULL for all rows')
896
        limit_ref[0] = 0 # just create an empty pkeys table
892 897
    def ignore(in_col, value):
893 898
        in_col_str = str(in_col)
894 899
        db.log_debug('Adding index on '+in_col_str+' to enable fast filtering')
......
939 944
            out_col, = e.cols
940 945
            try: in_col = mapping[out_col]
941 946
            except KeyError:
942
                db.log_debug('Missing mapping for NOT NULL '+out_col)
943
                limit = 0 # just create an empty pkeys table
947
                remove_all_rows('Missing mapping for NOT NULL '+out_col)
944 948
            else: remove_rows(in_col, None)
945 949
        except FunctionValueException, e:
946 950
            log_exc(e)
......
948 952
            assert e.name == out_table.name
949 953
            out_col = 'value' # assume function param was named "value"
950 954
            invalid2null(mapping[out_col], e.value)
955
        except DatabaseErrors, e:
956
            log_exc(e)
957
            
958
            remove_all_rows('No handler for exception: '+exc.str_(e))
951 959
        # after exception handled, rerun loop with additional constraints
952 960
    
953 961
    if row_ct_ref != None and cur.rowcount >= 0:

Also available in: Unified diff