MCPcopy Index your code
hub / github.com/MagicStack/asyncpg / reload_schema_state

Method reload_schema_state

asyncpg/connection.py:1816–1859  ·  view source on GitHub ↗

Indicate that the database schema information must be reloaded. For performance reasons, asyncpg caches certain aspects of the database schema, such as the layout of composite types. Consequently, when the database schema changes, and asyncpg is not able to graceful

(self)

Source from the content-addressed store, hash-verified

1814 self._drop_local_type_cache()
1815
1816 async def reload_schema_state(self):
1817 """Indicate that the database schema information must be reloaded.
1818
1819 For performance reasons, asyncpg caches certain aspects of the
1820 database schema, such as the layout of composite types. Consequently,
1821 when the database schema changes, and asyncpg is not able to
1822 gracefully recover from an error caused by outdated schema
1823 assumptions, an :exc:`~asyncpg.exceptions.OutdatedSchemaCacheError`
1824 is raised. To prevent the exception, this method may be used to inform
1825 asyncpg that the database schema has changed.
1826
1827 Example:
1828
1829 .. code-block:: pycon
1830
1831 >>> import asyncpg
1832 >>> import asyncio
1833 >>> async def change_type(con):
1834 ... result = await con.fetch('SELECT id, info FROM tbl')
1835 ... # Change composite's attribute type "int"=>"text"
1836 ... await con.execute('ALTER TYPE custom DROP ATTRIBUTE y')
1837 ... await con.execute('ALTER TYPE custom ADD ATTRIBUTE y text')
1838 ... await con.reload_schema_state()
1839 ... for id_, info in result:
1840 ... new = (info['x'], str(info['y']))
1841 ... await con.execute(
1842 ... 'UPDATE tbl SET info=$2 WHERE id=$1', id_, new)
1843 ...
1844 >>> async def run():
1845 ... # Initial schema:
1846 ... # CREATE TYPE custom AS (x int, y int);
1847 ... # CREATE TABLE tbl(id int, info custom);
1848 ... con = await asyncpg.connect(user='postgres')
1849 ... async with con.transaction():
1850 ... # Prevent concurrent changes in the table
1851 ... await con.execute('LOCK TABLE tbl')
1852 ... await change_type(con)
1853 ...
1854 >>> asyncio.run(run())
1855
1856 .. versionadded:: 0.14.0
1857 """
1858 self._drop_global_type_cache()
1859 self._drop_global_statement_cache()
1860
1861 async def _execute(
1862 self,

Callers 3

_do_executeMethod · 0.95
wait_and_dropMethod · 0.80
__do_executeMethod · 0.80

Calls 2

Tested by 1

wait_and_dropMethod · 0.64