MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / clear_mappers

Function clear_mappers

lib/sqlalchemy/orm/_orm_constructors.py:2336–2361  ·  view source on GitHub ↗

Remove all mappers from all classes. .. versionchanged:: 1.4 This function now locates all :class:`_orm.registry` objects and calls upon the :meth:`_orm.registry.dispose` method of each. This function removes all instrumentation from classes and disposes of their associa

()

Source from the content-addressed store, hash-verified

2334
2335
2336def clear_mappers() -> None:
2337 """Remove all mappers from all classes.
2338
2339 .. versionchanged:: 1.4 This function now locates all
2340 :class:`_orm.registry` objects and calls upon the
2341 :meth:`_orm.registry.dispose` method of each.
2342
2343 This function removes all instrumentation from classes and disposes
2344 of their associated mappers. Once called, the classes are unmapped
2345 and can be later re-mapped with new mappers.
2346
2347 :func:`.clear_mappers` is *not* for normal use, as there is literally no
2348 valid usage for it outside of very specific testing scenarios. Normally,
2349 mappers are permanent structural components of user-defined classes, and
2350 are never discarded independently of their class. If a mapped class
2351 itself is garbage collected, its mapper is automatically disposed of as
2352 well. As such, :func:`.clear_mappers` is only for usage in test suites
2353 that reuse the same classes with different mappings, which is itself an
2354 extremely rare use case - the only such use case is in fact SQLAlchemy's
2355 own test suite, and possibly the test suites of other ORM extension
2356 libraries which intend to test various combinations of mapper construction
2357 upon a fixed set of classes.
2358
2359 """
2360
2361 mapperlib._dispose_registries(mapperlib._all_registries(), False)
2362
2363
2364# I would really like a way to get the Type[] here that shows up

Callers 15

teardown_testMethod · 0.90
_setupMethod · 0.90
teardown_testMethod · 0.90
teardown_testMethod · 0.90
teardown_testMethod · 0.90
teardown_testMethod · 0.90
setup_sessionMethod · 0.90
setup_sessionMethod · 0.90
test_no_mappersMethod · 0.90
baseMethod · 0.90
_do_mapper_testMethod · 0.90

Calls

no outgoing calls

Tested by 15

teardown_testMethod · 0.72
_setupMethod · 0.72
teardown_testMethod · 0.72
teardown_testMethod · 0.72
teardown_testMethod · 0.72
teardown_testMethod · 0.72
setup_sessionMethod · 0.72
setup_sessionMethod · 0.72
test_no_mappersMethod · 0.72
baseMethod · 0.72
_do_mapper_testMethod · 0.72