Skip to content

fix: use subscript access in versioned_column_properties#168

Merged
winwinashwin merged 2 commits into
corridor:mainfrom
pReya:fix/versioned-column-properties-dict-api-collision
May 11, 2026
Merged

fix: use subscript access in versioned_column_properties#168
winwinashwin merged 2 commits into
corridor:mainfrom
pReya:fix/versioned-column-properties-dict-api-collision

Conversation

@pReya
Copy link
Copy Markdown
Contributor

@pReya pReya commented May 5, 2026

Summary

versioned_column_properties (and the version-table builder that consumes it) currently fails on any model with a column whose name shadows a dict-API attribute of mapper.attrs — most notably values, keys, or items.

getattr(mapper.attrs, key) resolves to the bound method on the underlying ReadOnlyProperties namespace rather than the ColumnProperty, so the next prop.key access in utils.py raises:

AttributeError: 'function' object has no attribute 'key'

This blocks inserts on otherwise-valid versioned models. Switching to subscript (mapper.attrs[key]) bypasses normal attribute resolution and always returns the mapped property.

Changes

  • sqlalchemy_history/utils.py: swap getattr(mapper.attrs, key) for mapper.attrs[key] in versioned_column_properties.
  • tests/reported_bugs/: new regression test using a model with values, keys, and items columns. Verified to reproduce the original AttributeError against unfixed utils.py and to pass after the fix.
  • CHANGES.rst: add an Unreleased entry describing the fix.

Test plan

  • New regression test passes against patched utils.py
  • New regression test fails on main with the documented AttributeError
  • ruff check and ruff format --check clean on changed files
  • No change in pass/fail counts on tests/relationships/ between fixed and unfixed builds (pre-existing failures are unrelated)

🤖 Generated with Claude Code

`getattr(mapper.attrs, key)` silently returns a bound method when a
column name shadows a dict-API attribute on the namespace (notably
`values`, `keys`, `items`). Subsequent `prop.key` access then raises
`AttributeError: 'function' object has no attribute 'key'` on insert.

Switch to subscript (`mapper.attrs[key]`), which bypasses normal
attribute resolution and always returns the mapped property.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

coveralls commented May 8, 2026

Coverage Report for CI Build 25663163505

Warning

No base build found for commit 9249e28 on main.
Coverage changes can't be calculated without a base build.
If a base build is processing, this comment will update automatically when it completes.

Coverage: 95.136%

Details

  • Patch coverage: 24 of 24 lines across 2 files are fully covered (100%).

Uncovered Changes

No uncovered changes found.

Coverage Regressions

Requires a base build to compare against. How to fix this →


Coverage Stats

Coverage Status
Relevant Lines: 5407
Covered Lines: 5144
Line Coverage: 95.14%
Coverage Strength: 9.45 hits per line

💛 - Coveralls

Comment thread CHANGES.rst Outdated
@pReya pReya requested a review from winwinashwin May 11, 2026 09:55
Copy link
Copy Markdown
Contributor

@winwinashwin winwinashwin left a comment

Choose a reason for hiding this comment

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

Thanks!!

@winwinashwin winwinashwin merged commit c508c94 into corridor:main May 11, 2026
14 checks passed
@pReya pReya deleted the fix/versioned-column-properties-dict-api-collision branch May 11, 2026 12:59
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.

3 participants