sd = self._tx.get_dumper(item, Pg3Format.TEXT)
dumper = type(self)(self.cls, self._tx)
dumper.sub_dumper = sd
- if not isinstance(item, int):
- dumper.oid = self._get_range_oid(sd.oid)
- else:
+ if isinstance(item, int):
# postgres won't cast int4range -> int8range so we must use
# text format and unknown oid here
dumper.oid = INVALID_OID
+ elif isinstance(item, str) and sd.oid == INVALID_OID:
+ # Work around the normal mapping where text is dumped as unknown
+ dumper.oid = self._get_range_oid(self._types["text"].oid)
+ else:
+ dumper.oid = self._get_range_oid(sd.oid)
return dumper
def _get_item(self, obj: Range[Any]) -> Any:
Return the oid of the range from the oid of its elements.
Raise InterfaceError if not found.
-
- TODO: we shouldn't consider builtins only, but other adaptation
- contexts too
"""
info = self._types.get_range(sub_oid)
return info.oid if info else INVALID_OID
self,
context: Optional[AdaptContext] = None,
) -> None:
- # A new dumper is not required. However TODO we will need to register
- # the dumper in the adapters type registry, when we have one.
+
+ if context:
+ context.adapters.types.add(self)
# generate and register a customized text loader
loader: Type[Loader] = type(
info.register(conn)
cur = conn.cursor()
for i in range(1, 254):
- # TODO: when types registry is merged to adaptation context and we
- # are able to establish "the type of the range whose element is text",
- # this should work without ::testrange cast.
cur.execute(
"""
- select ascii(lower(%(r)s::testrange)) = %(low)s
- and ascii(upper(%(r)s::testrange)) = %(up)s
+ select ascii(lower(%(r)s)) = %(low)s
+ and ascii(upper(%(r)s)) = %(up)s
""",
{"r": Range(chr(i), chr(i + 1)), "low": i, "up": i + 1},
)