Skip to content

Exception handling does not catch some SQL error types #53

@kgutwin

Description

@kgutwin

I noticed that the following response from Aurora Postgresql Serverless V2 was not being captured as a specific PostgreSQL error, but instead reported as a generic DatabaseError:

An error occurred (DatabaseErrorException) when calling the ExecuteStatement operation: ERROR: update or delete on table "song_sheets" violates foreign key constraint "setlist_sheets_song_sheet_id_fkey" on table "setlist_sheets"; SQLState: 23503

This is because the regex that looks for the SQLState code in the error message is a little more specific than it needs to be:

res = re.search(r"ERROR: .*(?:\n |;) Position: (\d+); SQLState: (\w+)$", error_msg)

The Position: field is required to match, but it isn't passed along to the PostgreSQLError, so it seems superfluous. I'm not sure, but removing the Position: match would probably help with more than just the above error (ER_FOREIGN_KEY_VIOLATION).

Thanks for this package, it's very useful!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions