- Adaptation configuration is performed by changing the
`~psycopg.abc.AdaptContext.adapters` object of objects implementing the
- `~psycopg.abc.AdaptContext` protocols, for instance `~psycopg.Connection`
+ `~psycopg.abc.AdaptContext` protocol, for instance `~psycopg.Connection`
or `~psycopg.Cursor`.
- Every context object derived from another context inherits its adapters
- Dumpers and loaders are instantiated on demand by a `~Transformer` object
when a query is executed.
+.. note::
+ Changing adapters in a context only affects that context and its children
+ objects created *afterwards*; the objects already created are not
+ affected. For instance, changing the global context will only change newly
+ created connections, not the ones already existing.
+
.. _adapt-example-xml:
allowed as value but not as a key.
In order to use the |hstore| data type it is necessary to load it in a
-database using
+database using:
.. code:: none
`~psycopg.Cursor` is created from a `~psycopg.Connection`), the parent's
`!adapters` are used as template for the child's `!adapters`, so that every
cursor created from the same connection use the connection's types
- configuration, but separate connections have independent mappings. Once
- created, `!AdaptersMap` are independent.
+ configuration, but separate connections have independent mappings.
+
+ Once created, `!AdaptersMap` are independent. This means that objects
+ already created are not affected if a wider scope (e.g. the global one) is
+ changed.
The connections adapters are initialised using a global `!AdptersMap`
template, exposed as `psycopg.adapters`: changing such mapping allows to
- customise the type mapping for the entire application.
+ customise the type mapping for every connections created afterwards.
The object can start empty or copy from another object of the same class.
Copies are copy-on-write: if the maps are updated make a copy. This way
extending e.g. global map by a connection or a connection map from a cursor
- is cheap: a copy is made only on customisation.
+ is cheap: a copy is only made on customisation.
"""
__module__ = "psycopg.adapt"
register it globally.
:param factory: Callable to convert the sequence of attributes read from
the composite into a Python object.
+
+ .. note::
+
+ Registering the adapters doesn't affect objects already created, even
+ if they are children of the registered context. For instance,
+ registering the adapter globally doesn't affect already existing
+ connections.
"""
# A friendly error warning instead of an AttributeError in case fetch()
:param info: The object with the information about the hstore type.
:param context: The context where to register the adapters. If `!None`,
register it globally.
+
+ .. note::
+
+ Registering the adapters doesn't affect objects already created, even
+ if they are children of the registered context. For instance,
+ registering the adapter globally doesn't affect already existing
+ connections.
"""
# A friendly error warning instead of an AttributeError in case fetch()
# failed and it wasn't noticed.
Register loaders so that loading data of this type will result in a `Range`
with bounds parsed as the right subtype.
+
+ .. note::
+
+ Registering the adapters doesn't affect objects already created, even
+ if they are children of the registered context. For instance,
+ registering the adapter globally doesn't affect already existing
+ connections.
"""
# A friendly error warning instead of an AttributeError in case fetch()
# failed and it wasn't noticed.
:param context: The context where to register the adapters. If `!None`,
register it globally.
+ .. note::
+
+ Registering the adapters doesn't affect objects already created, even
+ if they are children of the registered context. For instance,
+ registering the adapter globally doesn't affect already existing
+ connections.
"""
# A friendly error warning instead of an AttributeError in case fetch()