summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/ext/declarative/extensions.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2021-03-18 11:59:16 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2021-03-18 13:12:34 -0400
commitdfce8c35d3f95c401957f4d0ddaf8c7f49f52ece (patch)
tree44bd505932dab87b629110c52afd1c05d497f307 /lib/sqlalchemy/ext/declarative/extensions.py
parent3fec5028e695ad138aa46a0ae66c55e8bcb653f6 (diff)
downloadsqlalchemy-dfce8c35d3f95c401957f4d0ddaf8c7f49f52ece.tar.gz
Raise at Core / ORM concrete inh level for label overlap
Fixed regression where the :class:`.ConcreteBase` would fail to map at all when a mapped column name overlapped with the discriminator column name, producing an assertion error. The use case here did not function correctly in 1.3 as the polymorphic union would produce a query that ignored the discriminator column entirely, while emitting duplicate column warnings. As 1.4's architecture cannot easily reproduce this essentially broken behavior of 1.3 at the ``select()`` level right now, the use case now raises an informative error message instructing the user to use the ``.ConcreteBase._concrete_discriminator_name`` attribute to resolve the conflict. To assist with this configuration, ``.ConcreteBase._concrete_discriminator_name`` may be placed on the base class only where it will be automatically used by subclasses; previously this was not the case. Fixes: #6090 Change-Id: I8b7d01e4c9ea0dc97f30b8cd658b3505b24312a7
Diffstat (limited to 'lib/sqlalchemy/ext/declarative/extensions.py')
-rw-r--r--lib/sqlalchemy/ext/declarative/extensions.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/sqlalchemy/ext/declarative/extensions.py b/lib/sqlalchemy/ext/declarative/extensions.py
index 5c6356d8b..fd8bed6be 100644
--- a/lib/sqlalchemy/ext/declarative/extensions.py
+++ b/lib/sqlalchemy/ext/declarative/extensions.py
@@ -15,7 +15,6 @@ from ...orm import relationships
from ...orm.base import _mapper_or_none
from ...orm.clsregistry import _resolver
from ...orm.decl_base import _DeferredMapperConfig
-from ...orm.decl_base import _get_immediate_cls_attr
from ...orm.util import polymorphic_union
from ...schema import Table
from ...util import OrderedDict
@@ -86,6 +85,13 @@ class ConcreteBase(object):
attribute to :class:`_declarative.ConcreteBase` so that the
virtual discriminator column name can be customized.
+ .. versionchanged:: 1.4.2 The ``_concrete_discriminator_name`` attribute
+ need only be placed on the basemost class to take correct effect for
+ all subclasses. An explicit error message is now raised if the
+ mapped column names conflict with the discriminator name, whereas
+ in the 1.3.x series there would be some warnings and then a non-useful
+ query would be generated.
+
.. seealso::
:class:`.AbstractConcreteBase`
@@ -112,8 +118,7 @@ class ConcreteBase(object):
return
discriminator_name = (
- _get_immediate_cls_attr(cls, "_concrete_discriminator_name")
- or "type"
+ getattr(cls, "_concrete_discriminator_name", None) or "type"
)
mappers = list(m.self_and_descendants)
@@ -264,8 +269,7 @@ class AbstractConcreteBase(ConcreteBase):
mappers.append(mn)
discriminator_name = (
- _get_immediate_cls_attr(cls, "_concrete_discriminator_name")
- or "type"
+ getattr(cls, "_concrete_discriminator_name", None) or "type"
)
pjoin = cls._create_polymorphic_union(mappers, discriminator_name)