summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/interfaces.py
diff options
context:
space:
mode:
authormike bayer <mike_mp@zzzcomputing.com>2022-10-28 13:57:40 +0000
committerGerrit Code Review <gerrit@ci3.zzzcomputing.com>2022-10-28 13:57:40 +0000
commit718d9570f278be47eae2dc5dae0d218052aeffb9 (patch)
tree4422b0ccca3e78e8b5f22b35da8971c414e2d384 /lib/sqlalchemy/orm/interfaces.py
parent50d3b85c693a4ca673bcabd711f130ae58111f16 (diff)
parent73be84ae46473703dcf7b8d39e9666496fb07c8f (diff)
downloadsqlalchemy-718d9570f278be47eae2dc5dae0d218052aeffb9.tar.gz
Merge "ensure inherited mapper attrs not interpreted as plain dataclass fields" into main
Diffstat (limited to 'lib/sqlalchemy/orm/interfaces.py')
-rw-r--r--lib/sqlalchemy/orm/interfaces.py20
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/interfaces.py b/lib/sqlalchemy/orm/interfaces.py
index 9903c5f4a..1747bfd9b 100644
--- a/lib/sqlalchemy/orm/interfaces.py
+++ b/lib/sqlalchemy/orm/interfaces.py
@@ -213,7 +213,11 @@ class _AttributeOptions(NamedTuple):
@classmethod
def _get_arguments_for_make_dataclass(
- cls, key: str, annotation: Type[Any], elem: _T
+ cls,
+ key: str,
+ annotation: Type[Any],
+ mapped_container: Optional[Any],
+ elem: _T,
) -> Union[
Tuple[str, Type[Any]], Tuple[str, Type[Any], dataclasses.Field[Any]]
]:
@@ -229,7 +233,21 @@ class _AttributeOptions(NamedTuple):
elif elem is not _NoArg.NO_ARG:
# why is typing not erroring on this?
return (key, annotation, elem)
+ elif mapped_container is not None:
+ # it's Mapped[], but there's no "element", which means declarative
+ # did not actually do anything for this field. this shouldn't
+ # happen.
+ # previously, this would occur because _scan_attributes would
+ # skip a field that's on an already mapped superclass, but it
+ # would still include it in the annotations, leading
+ # to issue #8718
+
+ assert False, "Mapped[] received without a mapping declaration"
+
else:
+ # plain dataclass field, not mapped. Is only possible
+ # if __allow_unmapped__ is set up. I can see this mode causing
+ # problems...
return (key, annotation)