mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 00:46:33 +03:00
Fixed search of types into schemas.
We don't need to look for stuff implicitly into pg_catalog as all the builtin ranges are already registered. So just search into 'public' if the schema is not specified.
This commit is contained in:
parent
a1a2772a79
commit
a858987844
|
@ -291,7 +291,7 @@ class RangeCaster(object):
|
|||
schema, tname = name.split('.', 1)
|
||||
else:
|
||||
tname = name
|
||||
schema = None
|
||||
schema = 'public'
|
||||
|
||||
# get the type oid and attributes
|
||||
try:
|
||||
|
@ -301,8 +301,8 @@ select rngtypid, rngsubtype,
|
|||
from pg_range r
|
||||
join pg_type t on t.oid = rngtypid
|
||||
join pg_namespace ns on ns.oid = typnamespace
|
||||
where typname = %s and (%s is null or ns.nspname = %s);
|
||||
""", (tname, schema, schema))
|
||||
where typname = %s and ns.nspname = %s;
|
||||
""", (tname, schema))
|
||||
|
||||
except ProgrammingError:
|
||||
if not conn.autocommit:
|
||||
|
|
|
@ -1242,6 +1242,33 @@ class RangeCasterTestCase(unittest.TestCase):
|
|||
self.assertRaises(psycopg2.ProgrammingError,
|
||||
register_range, 'nosuchrange', 'FailRange', cur)
|
||||
|
||||
def test_schema_range(self):
|
||||
cur = self.conn.cursor()
|
||||
cur.execute("create schema rs")
|
||||
cur.execute("create type r1 as range (subtype=text)")
|
||||
cur.execute("create type r2 as range (subtype=text)")
|
||||
cur.execute("create type rs.r2 as range (subtype=text)")
|
||||
cur.execute("create type rs.r3 as range (subtype=text)")
|
||||
cur.execute("savepoint x")
|
||||
|
||||
from psycopg2.extras import register_range
|
||||
ra1 = register_range('r1', 'r1', cur)
|
||||
ra2 = register_range('r2', 'r2', cur)
|
||||
rars2 = register_range('rs.r2', 'r2', cur)
|
||||
rars3 = register_range('rs.r3', 'r3', cur)
|
||||
|
||||
self.assertNotEqual(
|
||||
ra2.typecaster.values[0],
|
||||
rars2.typecaster.values[0])
|
||||
|
||||
self.assertRaises(psycopg2.ProgrammingError,
|
||||
register_range, 'r3', 'FailRange', cur)
|
||||
cur.execute("rollback to savepoint x;")
|
||||
|
||||
self.assertRaises(psycopg2.ProgrammingError,
|
||||
register_range, 'rs.r1', 'FailRange', cur)
|
||||
cur.execute("rollback to savepoint x;")
|
||||
|
||||
decorate_all_tests(RangeCasterTestCase, skip_if_no_range)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user