(
registries: Set[_RegistryType], cascade: bool
)
| 4223 | |
| 4224 | @util.preload_module("sqlalchemy.orm.decl_api") |
| 4225 | def _do_configure_registries( |
| 4226 | registries: Set[_RegistryType], cascade: bool |
| 4227 | ) -> Iterator[registry]: |
| 4228 | registry = util.preloaded.orm_decl_api.registry |
| 4229 | |
| 4230 | orig = set(registries) |
| 4231 | |
| 4232 | for reg in registry._recurse_with_dependencies(registries): |
| 4233 | if reg._new_mappers: |
| 4234 | reg.dispatch.before_configured(reg) |
| 4235 | |
| 4236 | has_skip = False |
| 4237 | |
| 4238 | for mapper in reg._mappers_to_configure(): |
| 4239 | run_configure = None |
| 4240 | |
| 4241 | for fn in mapper.dispatch.before_mapper_configured: |
| 4242 | run_configure = fn(mapper, mapper.class_) |
| 4243 | if run_configure is EXT_SKIP: |
| 4244 | has_skip = True |
| 4245 | break |
| 4246 | if run_configure is EXT_SKIP: |
| 4247 | continue |
| 4248 | |
| 4249 | if getattr(mapper, "_configure_failed", False): |
| 4250 | e = sa_exc.InvalidRequestError( |
| 4251 | "One or more mappers failed to initialize - " |
| 4252 | "can't proceed with initialization of other " |
| 4253 | "mappers. Triggering mapper: '%s'. " |
| 4254 | "Original exception was: %s" |
| 4255 | % (mapper, mapper._configure_failed) |
| 4256 | ) |
| 4257 | e._configure_failed = mapper._configure_failed # type: ignore |
| 4258 | raise e |
| 4259 | |
| 4260 | if not mapper.configured: |
| 4261 | try: |
| 4262 | mapper._post_configure_properties() |
| 4263 | mapper._expire_memoizations() |
| 4264 | mapper.dispatch.mapper_configured(mapper, mapper.class_) |
| 4265 | except Exception: |
| 4266 | exc = sys.exc_info()[1] |
| 4267 | if not hasattr(exc, "_configure_failed"): |
| 4268 | mapper._configure_failed = exc |
| 4269 | raise |
| 4270 | |
| 4271 | if reg._new_mappers: |
| 4272 | yield reg |
| 4273 | if not has_skip: |
| 4274 | reg._new_mappers = False |
| 4275 | |
| 4276 | if not cascade and reg._dependencies.difference(orig): |
| 4277 | raise sa_exc.InvalidRequestError( |
| 4278 | "configure was called with cascade=False but " |
| 4279 | "additional registries remain" |
| 4280 | ) |
| 4281 | |
| 4282 |
no test coverage detected