Skip to content

Commit 5e23ed4

Browse files
author
James William Pye
committed
Add errcodes from 8.4.
Adjust LimitValueError to use the new SQL defined code. However, use the 'pg_code' attribute to allow for lookups from past versions to target the same exception.
1 parent b38ab48 commit 5e23ed4

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

postgresql/exceptions.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ class GrantorOperationError(GrantorError):
266266
class RoleSpecificationError(Error):
267267
code = '0P000'
268268

269+
class CaseNotFoundError(Error):
270+
code = '20000'
271+
269272
class CardinalityError(Error):
270273
"Wrong number of rows returned"
271274
code = '21000'
@@ -419,6 +422,12 @@ class InsufficientPrivilegeError(SEARVError):
419422
code = '42501'
420423
class GroupingError(SEARVError):
421424
code = '42803'
425+
426+
class RecursionError(SEARVError):
427+
code = '42P19'
428+
class WindowError(SEARVError):
429+
code = '42P20'
430+
422431
class SyntaxError(SEARVError):
423432
code = '42601'
424433

@@ -622,8 +631,13 @@ class TrimError(DataError):
622631
code = '22027'
623632
class IndicatorParameterValueError(DataError):
624633
code = '22010'
634+
625635
class LimitValueError(DataError):
626-
code = '22020'
636+
code = '2201W'
637+
pg_code = '22020'
638+
class OffsetValueError(DataError):
639+
code = '2201X'
640+
627641
class ParameterValueError(DataError):
628642
code = '22023'
629643
class RegularExpressionError(DataError):
@@ -718,6 +732,10 @@ def map_errors_and_warnings(
718732
# there are sub-Class types that share the Class code
719733
# with the most general type. (See TypeError)
720734
container[code] = obj
735+
if hasattr(obj, 'pg_code'):
736+
# If there's a PostgreSQL version of the code,
737+
# map it as well for older servers.
738+
container[obj.pg_code] = obj
721739

722740
def code_lookup(
723741
default : "The object to return when no code or class is found",

postgresql/test/test_exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
import postgresql.exceptions as pg_exc
77

88
class test_exceptions(unittest.TestCase):
9+
def test_pg_code_lookup(self):
10+
# in 8.4, pg started using the SQL defined error code for limits
11+
# Users *will* get whatever code PG sends, but it's important
12+
# that they have some way to abstract it. many-to-one map ftw.
13+
self.failUnless(
14+
pg_exc.ErrorLookup('22020') == pg_exc.LimitValueError
15+
)
16+
917
def test_error_lookup(self):
1018
# An error code that doesn't exist yields pg_exc.Error
1119
self.failUnless(

0 commit comments

Comments
 (0)