Project

General

Profile

« Previous | Next » 

Revision 3095

sql.py: run_query(): Exception parsing: Match patterns only at the beginning of the exception message to avoid matching embedded messages in causes and literal values

View differences:

sql.py
440 440
                return with_savepoint(db, run)
441 441
            else: return run() # don't need savepoint if cached
442 442
        except Exception, e:
443
            msg = exc.str_(e)
443
            msg = strings.ustr(e.args[0])
444 444
            
445
            match = re.search(r'duplicate key value violates unique constraint '
445
            match = re.match(r'^duplicate key value violates unique constraint '
446 446
                r'"((_?[^\W_]+)_.+?)"', msg)
447 447
            if match:
448 448
                constraint, table = match.groups()
......
452 452
                    except NotImplementedError: pass
453 453
                raise DuplicateKeyException(constraint, cols, e)
454 454
            
455
            match = re.search(r'null value in column "(.+?)" violates not-null'
455
            match = re.match(r'^null value in column "(.+?)" violates not-null'
456 456
                r' constraint', msg)
457 457
            if match: raise NullValueException('NOT NULL', [match.group(1)], e)
458 458
            
459
            match = re.search(r'\b(?:invalid input (?:syntax|value)\b.*?'
459
            match = re.match(r'^(?:invalid input (?:syntax|value)\b.*?'
460 460
                r'|date/time field value out of range): "(.+?)"\n'
461 461
                r'(?:(?s).*?)\bfunction "(.+?)"', msg)
462 462
            if match:
463 463
                value, name = match.groups()
464 464
                raise FunctionValueException(name, strings.to_unicode(value), e)
465 465
            
466
            match = re.search(r'column "(.+?)" is of type (.+?) but expression '
466
            match = re.match(r'^column "(.+?)" is of type (.+?) but expression '
467 467
                r'is of type', msg)
468 468
            if match:
469 469
                col, type_ = match.groups()
470 470
                raise MissingCastException(type_, col, e)
471 471
            
472
            match = re.search(r'\b(\S+) "(.+?)".*? already exists', msg)
472
            match = re.match(r'^(\S+) "(.+?)".*? already exists', msg)
473 473
            if match:
474 474
                type_, name = match.groups()
475 475
                raise DuplicateException(type_, name, e)

Also available in: Unified diff