diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2023-03-30 00:25:39 +0200 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2023-03-31 09:57:09 -0400 |
| commit | 96670516b917424e7dd4c6cee5e07147c583f6c9 (patch) | |
| tree | 50e53530f33859228b989d03228f6da14449c5b1 /lib | |
| parent | db69e680da3aa01572c19cdedb6448e74a01c790 (diff) | |
| download | sqlalchemy-96670516b917424e7dd4c6cee5e07147c583f6c9.tar.gz | |
Wrap dataclass exceptions clarifying origin
Exceptions such as ``TypeError`` and ``ValueError`` raised by Python
dataclasses when making use of the :class:`_orm.MappedAsDataclass` mixin
class or :meth:`_orm.registry.mapped_as_dataclass` decorator are now
wrapped within an :class:`.InvalidRequestError` wrapper along with
informative context about the error message, referring to the Python
dataclasses documentation as the authoritative source of background
information on the cause of the exception.
Fixes: #9563
Change-Id: I25652485b91c4ee8cf112b91aae8f9041061a8bd
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/sqlalchemy/orm/decl_base.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/sqlalchemy/orm/decl_base.py b/lib/sqlalchemy/orm/decl_base.py index 828501d8c..bd62c3c1b 100644 --- a/lib/sqlalchemy/orm/decl_base.py +++ b/lib/sqlalchemy/orm/decl_base.py @@ -1210,6 +1210,14 @@ class _ClassScanMapperConfig(_MapperConfig): if v is not _NoArg.NO_ARG and k != "dataclass_callable" }, ) + except (TypeError, ValueError) as ex: + raise exc.InvalidRequestError( + f"Python dataclasses error encountered when creating " + f"dataclass for {klass.__name__!r}: " + f"{ex!r}. Please refer to Python dataclasses " + "documentation for additional information.", + code="dcte", + ) from ex finally: # restore original annotations outside of the dataclasses # process; for mixins and __abstract__ superclasses, SQLAlchemy |
