-
Notifications
You must be signed in to change notification settings - Fork 28
Fix/mappedcolumn key attr #150
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
Changes from all commits
482930e
2d1e70c
28caf49
33b0e82
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,23 @@ | ||
| # ref: https://dev.to/m1yag1/how-to-setup-your-project-with-pre-commit-black-and-flake8-183k | ||
| repos: | ||
| - repo: https://github.com/pre-commit/pre-commit-hooks | ||
| rev: v2.0.0 | ||
| hooks: | ||
| - id: flake8 | ||
| - repo: https://github.com/astral-sh/ruff-pre-commit | ||
| rev: 'v0.0.292' | ||
| rev: v0.11.10 | ||
| hooks: | ||
| - id: ruff | ||
| name: ruff | ||
| files: ^(sqlalchemy_history|tests)/.*\.py$ | ||
| additional_dependencies: | ||
| - httpx~=0.24.1 | ||
| - tornado~=6.3.3 | ||
| - APScheduler~=3.10.4 | ||
| - cachetools~=5.3.1 | ||
| - aiolimiter~=1.1.0 | ||
| # Run the linter. | ||
| - id: ruff-check | ||
| args: [ --fix ] | ||
| files: ^(sqlalchemy_history|tests)/.*\.py$ | ||
| additional_dependencies: | ||
| - httpx~=0.24.1 | ||
| - tornado~=6.3.3 | ||
| - APScheduler~=3.10.4 | ||
| - cachetools~=5.3.1 | ||
| - aiolimiter~=1.1.0 | ||
| # Run the formatter. | ||
| - id: ruff-format | ||
| files: ^(sqlalchemy_history|tests)/.*\.py$ | ||
| additional_dependencies: | ||
| - httpx~=0.24.1 | ||
| - tornado~=6.3.3 | ||
| - APScheduler~=3.10.4 | ||
| - cachetools~=5.3.1 | ||
| - aiolimiter~=1.1.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,9 +9,9 @@ version = "0" | |
| authors = ["Corridor Platforms <postmaster@corridorplatforms.com>"] | ||
| license = "Apache-2.0, BSD-3-Clause" | ||
| readme = "docs/README.md" | ||
| packages = [{include = "sqlalchemy_history"}] | ||
| packages = [{ include = "sqlalchemy_history" }] | ||
| repository = "https://github.com/corridor/sqlalchemy-history" | ||
| classifiers=[ | ||
| classifiers = [ | ||
| "Intended Audience :: Developers", | ||
| "Operating System :: OS Independent", | ||
| "Programming Language :: Python", | ||
|
|
@@ -47,6 +47,96 @@ pytest-cov = "*" | |
| line-length = 110 | ||
| target-version = ['py37'] | ||
|
|
||
| [tool.ruff] | ||
| # Exclude a variety of commonly ignored directories. | ||
| exclude = [ | ||
| ".bzr", | ||
| ".direnv", | ||
| ".eggs", | ||
| ".git", | ||
| ".git-rewrite", | ||
| ".hg", | ||
| ".ipynb_checkpoints", | ||
| ".mypy_cache", | ||
| ".nox", | ||
| ".pants.d", | ||
| ".pyenv", | ||
| ".pytest_cache", | ||
| ".pytype", | ||
| ".ruff_cache", | ||
| ".svn", | ||
| ".tox", | ||
| ".venv", | ||
| ".vscode", | ||
| "__pypackages__", | ||
| "_build", | ||
| "buck-out", | ||
| "build", | ||
| "dist", | ||
| "node_modules", | ||
| "site-packages", | ||
| "venv", | ||
| ] | ||
|
|
||
| # Same as Black. | ||
| line-length = 110 | ||
| indent-width = 4 | ||
|
|
||
| [tool.ruff.lint] | ||
| # Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default. | ||
| # Enable flake8-bugbear (`B`) rules, in addition to the defaults | ||
| # Enable isort (`I`) rules, in addition to the defaults | ||
| select = [ | ||
| # pycodestyle | ||
| "E", | ||
| # Pyflakes | ||
| "F", | ||
| # pyupgrade | ||
| #"UP", | ||
| # flake8-bugbear | ||
| "B", | ||
| # flake8-simplify | ||
| #"SIM", | ||
| # isort | ||
| "I", | ||
| ] | ||
| ignore = [] | ||
|
|
||
| # Allow fix for all enabled rules (when `--fix`) is provided. | ||
| fixable = ["ALL"] | ||
| unfixable = [] | ||
|
|
||
| # Allow unused variables when underscore-prefixed. | ||
| dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.format] | ||
| # Like Black, use double quotes for strings. | ||
| quote-style = "double" | ||
|
|
||
| # Like Black, indent with spaces, rather than tabs. | ||
| indent-style = "space" | ||
|
|
||
| # Like Black, respect magic trailing commas. | ||
| skip-magic-trailing-comma = false | ||
|
|
||
| # Like Black, automatically detect the appropriate line ending. | ||
| line-ending = "auto" | ||
|
|
||
| # Enable auto-formatting of code examples in docstrings. Markdown, | ||
| # reStructuredText code/literal blocks and doctests are all supported. | ||
| # | ||
| # This is currently disabled by default, but it is planned for this | ||
| # to be opt-out in the future. | ||
| docstring-code-format = false | ||
|
|
||
| # Set the line length limit used when formatting code snippets in | ||
| # docstrings. | ||
| # | ||
| # This only has an effect when the `docstring-code-format` setting is | ||
| # enabled. | ||
| docstring-code-line-length = "dynamic" | ||
|
|
||
|
|
||
| [tool.coverage.run] | ||
| dynamic_context = "test_function" | ||
| branch = true | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| """Model Builder module build Versioned Models | ||
| """ | ||
| """Model Builder module build Versioned Models""" | ||
|
|
||
| from copy import copy | ||
|
|
||
| import sqlalchemy as sa | ||
| from sqlalchemy.ext.declarative import declared_attr | ||
| from sqlalchemy.orm import column_property | ||
| from sqlalchemy.orm import MappedColumn, column_property | ||
| from sqlalchemy_utils.functions import get_declarative_base, get_primary_keys | ||
| from sqlalchemy_utils.models import generic_repr | ||
|
|
||
|
|
@@ -82,15 +83,17 @@ def copy_mapper_args(model): | |
| args[arg] = model.__mapper_args__[arg] | ||
|
|
||
| if "polymorphic_on" in model.__mapper_args__: | ||
| column = model.__mapper_args__["polymorphic_on"] | ||
| if isinstance(column, str): | ||
| args["polymorphic_on"] = column | ||
| 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 | ||
|
Comment on lines
+86
to
+92
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What really matters in this PR
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is really helpful @lukasab, Is it ok if i moved the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| return args | ||
|
|
||
|
|
||
| class ModelBuilder(object): | ||
| class ModelBuilder: | ||
| """VersionedModelBuilder handles the building of Version models based on parent table attributes and | ||
| versioning configuration.""" | ||
|
|
||
|
|
@@ -244,7 +247,10 @@ def mapper_args(cls): | |
| name = "%sVersion" % (self.model.__name__,) | ||
| version_cls = type(name, self.base_classes(), args) | ||
| if option(self.model, "base_classes") is None: | ||
| primary_keys = list(get_primary_keys(self.model).keys()) + ["transaction_id", "operation_type"] | ||
| primary_keys = list(get_primary_keys(self.model).keys()) + [ | ||
| "transaction_id", | ||
| "operation_type", | ||
| ] | ||
| version_cls = generic_repr(*primary_keys)(version_cls) | ||
| return version_cls | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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