see #10027. MappedAsDataclass basically cannot support the dataclass "init" feature on a class that isn't mapped, and likely can't support any dataclass features on such a class as instantiated. Propose instantiation of mixins / abstract emit a warning if they are also "dataclass" produced under 2.0, error in 2.1.
For unmapped mixin and abstract classes transformed by _UnmappedDataclassConfig, we can wrap or replace the generated init with a check that emits an SAWarning (or raises in 2.1) if the abstract/mixin class is directly instantiated, while allowing concrete mapped subclasses to generate their proper dataclass constructor.
Could you please add the "open for pull requests" label if you'd like a PR for this?
Activity
VimalN2005 commented on Sep 12, 2026
Hi @zzzeek,
I'd like to take this on.
For unmapped mixin and abstract classes transformed by _UnmappedDataclassConfig, we can wrap or replace the generated init with a check that emits an SAWarning (or raises in 2.1) if the abstract/mixin class is directly instantiated, while allowing concrete mapped subclasses to generate their proper dataclass constructor.
Could you please add the "open for pull requests" label if you'd like a PR for this?
zzzeek commented on Sep 12, 2026
sure....let's just have this warn in 2.1 for now
VimalN2005 commented on Sep 12, 2026
Thanks @zzzeek! Having it emit an SAWarning in 2.1 makes total sense. I've aligned the implementation and opened the PR for review.
sqla-tester commented on Sep 24, 2026
VimalN2005 has proposed a fix for this issue in the main branch:
Emit warning on direct instantiation of unmapped MappedAsDataclass https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6991
Emit warning on direct instantiation of unmapped MappedAsDataclass
zzzeek commented on Sep 24, 2026
we're in RCs for 2.1 and I want to hold on this one until post-2.1. once 2.1 is smooth sailing we can look at a warning for this
Emit warning on direct instantiation of unmapped MappedAsDataclass