Skip to content

Add dataclass_metadata parameter to mapped_column and friends. #12619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

slahn
Copy link

@slahn slahn commented May 23, 2025

Description

Field.metadata in python dataclasses is an extension mechanism.
It's used by some serialization libraries like xsdata and desert.

See #10674 and this discussion for more context.

This PR adds the parameter dataclass_metadata to mapped_column(), column_property(), composite(), relationship(), synonym(), deferred(), and query_expressions.

Updates nessescary property and mapping tests.
Adds a new test DCTransformsTest.test_dataclass_metadata.

The parameter name, dataclass_metadata, was suggested in #10674.
The name in _AttributeOptions, dataclasses_dataclass_metadata, was chosen to match the other parameters, as well as what tests expect.

Checklist

This pull request is:

  • A documentation / typographical / small typing error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

This parameter is then passed to `dataclasses.field()` if mapped as a
dataclass.

Fixes: sqlalchemy#10674
@slahn
Copy link
Author

slahn commented May 23, 2025

Missing docstrings for new parameters, but I'd like feedback on the general approach. Maybe there's something I've forgotten? I'm not well versed in sqlalchemy internals.

@CaselIT
Copy link
Member

CaselIT commented May 23, 2025

Seems like a great start thanks!

@zzzeek
Copy link
Member

zzzeek commented Jul 3, 2025

can we target this for 2.1 or do you need this in a hurry?

@zzzeek zzzeek requested a review from sqla-tester July 3, 2025 16:14
Copy link
Collaborator

@sqla-tester sqla-tester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, this is sqla-tester setting up my work on behalf of zzzeek to try to get revision 9ea6a95 of this pull request into gerrit so we can run tests and reviews and stuff

@sqla-tester
Copy link
Collaborator

New Gerrit review created for change 9ea6a95: https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6024

@sqla-tester
Copy link
Collaborator

Michael Bayer (zzzeek) wrote:

recheck

want to see why this failed

View this in Gerrit at https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/6024

@zzzeek
Copy link
Member

zzzeek commented Jul 10, 2025

hi -

if you're still working on this, need to run python tools/sync_test_files.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy