Skip to content

Add dataclasses field "hash" parameter in mapped_column() #11923

@CaselIT

Description

@CaselIT

Discussed in #11894

Originally posted by arimeyer September 19, 2024
On standard dataclasses there is a hash parameter on dataclasses.field: https://docs.python.org/3/library/dataclasses.html#module-contents . When trying to convert from SA 1.4 dataclasses to 2.0, I tried following:
https://docs.sqlalchemy.org/en/20/orm/dataclasses.html#attribute-configuration
https://docs.sqlalchemy.org/en/20/orm/mapping_api.html#sqlalchemy.orm.mapped_column

There was no mention about the "hash" parameter being specifically unsupported in mapped_column(), but when I add it to mirror my 1.4 code and set hash=False for certain fields, I get:
TypeError: init() got an unexpected keyword argument 'hash'

Was this deliberate? If so, what is the workaround?

Metadata

Metadata

Assignees

No one assigned

    Labels

    PRs (with tests!) welcomea fix or feature which is appropriate to be implemented by volunteersdataclassesormorm - annotated declarativeissues with the new annotations-based declarative ORM approachuse casenot really a feature or a bug; can be support for new DB features or user use cases not anticipated

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions