diff options
| author | Gord Thompson <gord@gordthompson.com> | 2021-08-12 13:04:28 -0600 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2021-09-30 10:10:16 -0400 |
| commit | 257f9130c321aaa948690d0e49c7352ad1188abd (patch) | |
| tree | 2648c88460c3e5de847ee998edb7a6df0aa9b261 /lib/sqlalchemy/orm/decl_base.py | |
| parent | f7f2df607301afcd11dd49a2ccb632291de12d29 (diff) | |
| download | sqlalchemy-257f9130c321aaa948690d0e49c7352ad1188abd.tar.gz | |
Modernize tests - calling_mapper_directly
a few changes for py2k:
* map_imperatively() includes the check that a class
is being sent, this was only working for mapper() before
* the test suite didn't place the py2k "autouse" workaround
in the correct order, seemingly, tried to adjust the
per-test ordering setup in pytestplugin.py
Change-Id: I4cc39630724e810953cfda7b2afdadc8b948e3c2
Diffstat (limited to 'lib/sqlalchemy/orm/decl_base.py')
| -rw-r--r-- | lib/sqlalchemy/orm/decl_base.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py index e1945e8ee..bf1bc537d 100644 --- a/lib/sqlalchemy/orm/decl_base.py +++ b/lib/sqlalchemy/orm/decl_base.py @@ -176,19 +176,28 @@ class _MapperConfig(object): return cfg_cls(registry, cls_, dict_, table, mapper_kw) - def __init__(self, registry, cls_): - self.cls = cls_ + def __init__(self, registry, cls_, mapper_kw): + self.cls = util.assert_arg_type(cls_, type, "cls_") self.classname = cls_.__name__ self.properties = util.OrderedDict() self.declared_attr_reg = {} - instrumentation.register_class( - self.cls, - finalize=False, - registry=registry, - declarative_scan=self, - init_method=registry.constructor, - ) + if not mapper_kw.get("non_primary", False): + instrumentation.register_class( + self.cls, + finalize=False, + registry=registry, + declarative_scan=self, + init_method=registry.constructor, + ) + else: + manager = attributes.manager_of_class(self.cls) + if not manager or not manager.is_mapped: + raise exc.InvalidRequestError( + "Class %s has no primary mapper configured. Configure " + "a primary mapper first before setting up a non primary " + "Mapper." % self.cls + ) def set_cls_attribute(self, attrname, value): @@ -210,15 +219,18 @@ class _ImperativeMapperConfig(_MapperConfig): table, mapper_kw, ): - super(_ImperativeMapperConfig, self).__init__(registry, cls_) + super(_ImperativeMapperConfig, self).__init__( + registry, cls_, mapper_kw + ) self.dict_ = {} self.local_table = self.set_cls_attribute("__table__", table) with mapperlib._CONFIGURE_MUTEX: - clsregistry.add_class( - self.classname, self.cls, registry._class_registry - ) + if not mapper_kw.get("non_primary", False): + clsregistry.add_class( + self.classname, self.cls, registry._class_registry + ) self._setup_inheritance(mapper_kw) @@ -288,7 +300,7 @@ class _ClassScanMapperConfig(_MapperConfig): mapper_kw, ): - super(_ClassScanMapperConfig, self).__init__(registry, cls_) + super(_ClassScanMapperConfig, self).__init__(registry, cls_, mapper_kw) self.dict_ = dict(dict_) if dict_ else {} self.persist_selectable = None |
