Skip to content

Support string attribute names for version_id_col (Fixes #6084) - #13596

Closed
Anurag-M1 wants to merge 1 commit into
sqlalchemy:mainfrom
Anurag-M1:fix-6084-version-id-col-string
Closed

Anurag-M1 wants to merge 1 commit into
sqlalchemy:mainfrom
Anurag-M1:fix-6084-version-id-col-string

Conversation

@Anurag-M1

Copy link
Copy Markdown

Description

Fixes #6084. Allows specifying string attribute or column names for the version_id_col parameter in Mapper and Declarative __mapper_args__.

During mapper configuration (_configure_version_id_col), string attribute or column names are resolved against _props and persist_selectable.c to the corresponding ColumnProperty, matching the established behavior of polymorphic_on.

Changes

  • Updated version_id_col parameter typing in Mapper.__init__ to accept strings and MapperProperty.
  • Added _configure_version_id_col method called during mapper construction to resolve strings and mapper properties into concrete columns, with validation for non-existent and non-column attributes.
  • Added comprehensive test suite in test/orm/test_versioning.py covering string attribute names, column names differing from property keys, dataclass mappings with metadata, and polymorphic inheritance.
  • Added changelog entry in doc/build/changelog/unreleased_21/6084.rst.

Checklist

This pull request is:

  • A documentation / typographical / small typing error fix
  • A short code fix
  • 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!

Allow specifying string attribute or column names for the
version_id_col parameter in Mapper and Declarative __mapper_args__.
During mapper configuration, string names are resolved against mapped
properties and the persist_selectable to the underlying ColumnProperty,
matching the behavior of polymorphic_on.

Fixes: sqlalchemy#6084
@sqla-tester

Copy link
Copy Markdown
Collaborator

Hi, and thanks for the pull request!

This project accepts pull requests only for issues that a maintainer has already marked with the open for pull requests label. That way we can settle on an approach before anyone spends time writing code.

This pull request references issue #6084, which hasn't been marked open for pull requests, so the change isn't authorized yet and I'm closing it automatically. Once a maintainer adds the label to #6084, reopen this pull request and it will stay open. If #6084 needs more detail before that can happen, a complete runnable example is usually the missing piece, and adding one to the issue is the fastest way to get there.

This is automatic and procedural. It isn't a judgment on your change, and nothing you've written here is lost.

Thanks for your interest in the project!

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.

version_id_col should accept string attr name like polymorphic_on does, make sure all mapper args that point to a column can work like this

2 participants