Skip to content

Fix/mappedcolumn key attr#150

Closed
lukasab wants to merge 4 commits intocorridor:masterfrom
lukasab:fix/mappedcolumn-key-attr
Closed

Fix/mappedcolumn key attr#150
lukasab wants to merge 4 commits intocorridor:masterfrom
lukasab:fix/mappedcolumn-key-attr

Conversation

@lukasab
Copy link

@lukasab lukasab commented Jun 1, 2025

What does this PR do?

  • Fixes AttributeError: 'MappedColumn' object has no attribute 'key' on SQLAlchemy ≥ 2.0

  • Code-quality pass with Ruff

    • Ran ruff format . for consistent modern formatting.
    • Fixed minor lint issues reported by ruff check / flake8
      (unused imports, spacing, etc.). No behavioural changes outside the bug
      fix above.

Motivation

Polymorphic, versioned models crash on SQLAlchemy 2.x because MappedColumn no longer exposes a top-level .key.
This PR resolves issue #149 and restores compatibility.

Lukas Alberto Belck added 2 commits June 1, 2025 23:25
- Ran ruff format on all repository files
- Ran ruff check --fix & and fixed B006, B007, B018, B904 e
@lukasab lukasab force-pushed the fix/mappedcolumn-key-attr branch from 253fe2d to 2d1e70c Compare June 1, 2025 22:23
Lukas Alberto Belck added 2 commits June 2, 2025 00:27
Install `freetds-dev` (and build-essentials) so `pymssql` can compile against the FreeTDS headers.
@lukasab lukasab force-pushed the fix/mappedcolumn-key-attr branch from 268ffe9 to 33b0e82 Compare June 1, 2025 22:51
@lukasab
Copy link
Author

lukasab commented Jun 1, 2025

Having some troubles with the tests for python 3.7 =/ now that ubuntu-20.04 is unsupported

Comment on lines +86 to +92
discriminator_column = model.__mapper_args__["polymorphic_on"]
if isinstance(discriminator_column, str):
args["polymorphic_on"] = discriminator_column
elif isinstance(discriminator_column, MappedColumn):
args["polymorphic_on"] = discriminator_column.column.key
else:
args["polymorphic_on"] = column.key
args["polymorphic_on"] = discriminator_column.key
Copy link
Author

Choose a reason for hiding this comment

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

What really matters in this PR

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is really helpful @lukasab, Is it ok if i moved the mappedcolumn fix to separate commit from the ruff-pre-commit change?

Copy link
Author

Choose a reason for hiding this comment

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

Of course, this being released would help me out as I'm trying to migrate to the new MappedColumn

unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
Copy link
Collaborator

Choose a reason for hiding this comment

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

some values here are the default ruff values, we can skip those and specify only the update values?

looks like we only the updated the select config

Copy link
Author

@lukasab lukasab Jun 2, 2025

Choose a reason for hiding this comment

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

Sure, I can remove the default values.

I was wondering which selects to use on the [tool.ruff.lint] section, but unsure who was maintaining the repo here to ask

python-version:
- "3.7"
- "3.12"
- "3.7.17"
Copy link
Collaborator

Choose a reason for hiding this comment

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

trying to understand why it was needed to fix to specific version?

Copy link
Author

Choose a reason for hiding this comment

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

Seems to be breaking because of the ubuntu os update required

test failed with:

The version '3.7' with architecture 'x64' was not found for Ubuntu 24.04. The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json

Copy link
Collaborator

Choose a reason for hiding this comment

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

found more on this: actions/setup-python#962

@lukasab
Copy link
Author

lukasab commented Jun 2, 2025

Is it planned to still support python 3.7 and 3.8? I believe sqlalchemy 2.x is supporting <=3.9

@ashish16052
Copy link
Collaborator

Is it planned to still support python 3.7 and 3.8? I believe sqlalchemy 2.x is supporting <=3.9

hmm, says otherwise here and in pypi

not sure if this is just documentation error?

@ashish16052
Copy link
Collaborator

@lukasab i was able to fix the CI test by pinning pymssql version to under 2.3.2

updated the commits in #151

@lukasab
Copy link
Author

lukasab commented Jun 5, 2025

I'll close this PR as you have opened a new one with the fixes. Thank you!

@lukasab lukasab closed this Jun 5, 2025
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.

2 participants