Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ jobs:
strategy:
matrix:
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

- "3.12.10"
DB:
- "sqlite"
- "mssql"
Expand Down Expand Up @@ -72,13 +72,17 @@ jobs:
--health-interval 30s
--health-timeout 15s
--health-retries 5
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v1
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install system libs for pymssql
run: |
sudo apt-get update
sudo apt-get install --yes build-essential freetds-dev freetds-bin
- name: Install Project
run: |
python -m pip install --upgrade pip
Expand Down Expand Up @@ -121,7 +125,7 @@ jobs:
uses: chartboost/ruff-action@v1

generate-coverage-report:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
needs: [test-sqlalchemy-history]
steps:
- name: Coveralls
Expand Down
35 changes: 20 additions & 15 deletions .pre-commit-config.yaml
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
15 changes: 8 additions & 7 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, close_all_sessions
from sqlalchemy_history import make_versioned, versioning_manager, remove_versioning
from sqlalchemy_history.transaction import TransactionFactory
from sqlalchemy.orm import close_all_sessions, sessionmaker
from termcolor import colored

from sqlalchemy_history import make_versioned, remove_versioning, versioning_manager
from sqlalchemy_history.plugins import (
PropertyModTrackerPlugin,
TransactionMetaPlugin,
TransactionChangesPlugin,
TransactionMetaPlugin,
)
from termcolor import colored
from sqlalchemy_history.transaction import TransactionFactory

warnings.simplefilter("error", sa.exc.SAWarning)

Expand Down Expand Up @@ -80,8 +81,8 @@ class Tag(Model):

start = time()

for i in range(20):
for i in range(20):
for _i in range(20):
for _i in range(20):
session.add(Article(name="Article", tags=[Tag(), Tag()]))
session.commit()

Expand Down
94 changes: 92 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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]+?))$"
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


[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
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import sqlalchemy as sa

from sqlalchemy_history.exc import ( # noqa: F401
ClassNotVersioned,
ImproperlyConfigured,
Expand All @@ -30,7 +31,6 @@
version_class,
)


__version__ = "2.1.4"


Expand Down
6 changes: 3 additions & 3 deletions sqlalchemy_history/builder.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
"""Builder Module Detects and builds version class for models and version tables collected during instrument
phase by the manager
phase by the manager
"""

from copy import copy
from inspect import getmro
from functools import wraps
from inspect import getmro

import sqlalchemy as sa
from sqlalchemy.orm.descriptor_props import ConcreteInheritedProperty
from sqlalchemy_utils.functions import get_declarative_base, get_hybrid_properties
from sqlalchemy_history.utils import get_association_proxies, version_class

from sqlalchemy_history.model_builder import ModelBuilder
from sqlalchemy_history.relationship_builder import RelationshipBuilder
from sqlalchemy_history.table_builder import TableBuilder
from sqlalchemy_history.utils import get_association_proxies, version_class


def prevent_reentry(handler):
Expand Down
6 changes: 3 additions & 3 deletions sqlalchemy_history/expression_reflector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""This is ExpressionReflector used for generating expression queries.
"""
"""This is ExpressionReflector used for generating expression queries."""

import sqlalchemy as sa
from sqlalchemy.sql.expression import bindparam

from sqlalchemy_history.utils import version_table
from sqlalchemy_history.exc import TableNotVersioned
from sqlalchemy_history.utils import version_table


class VersionExpressionReflector(sa.sql.visitors.ReplacingCloningVisitor):
Expand Down
8 changes: 5 additions & 3 deletions sqlalchemy_history/fetcher.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Fetcher Module helps traverse across versions for a given versioned object.
"""
"""Fetcher Module helps traverse across versions for a given versioned object."""

import operator

import sqlalchemy as sa
from sqlalchemy_utils import get_primary_keys, identity
from sqlalchemy_history.utils import tx_column_name, end_tx_column_name

from sqlalchemy_history.utils import end_tx_column_name, tx_column_name


def parent_identity(obj_or_class):
Expand Down
5 changes: 4 additions & 1 deletion sqlalchemy_history/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
and the actual versioning to UnitOfWork class.

"""

from functools import wraps

import sqlalchemy as sa
Expand Down Expand Up @@ -57,7 +58,7 @@ def __init__(
unit_of_work_cls=UnitOfWork,
transaction_cls=None,
user_cls=None,
options={},
options=None,
plugins=None,
builder=None,
):
Expand All @@ -66,6 +67,8 @@ def __init__(
self.builder = Builder()
else:
self.builder = builder
if options is None:
options = {}
self.builder.manager = self
self.reset()
if transaction_cls is not None:
Expand Down
24 changes: 15 additions & 9 deletions sqlalchemy_history/model_builder.py
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

Expand Down Expand Up @@ -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
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

return args


class ModelBuilder(object):
class ModelBuilder:
"""VersionedModelBuilder handles the building of Version models based on parent table attributes and
versioning configuration."""

Expand Down Expand Up @@ -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

Expand Down
6 changes: 2 additions & 4 deletions sqlalchemy_history/operation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Operations module contains Operation Class.
"""

from copy import copy
"""Operations module contains Operation Class."""

from collections import OrderedDict
from copy import copy

import sqlalchemy as sa
from sqlalchemy_utils import identity
Expand Down
2 changes: 1 addition & 1 deletion sqlalchemy_history/plugins/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
from sqlalchemy.inspection import inspect
from sqlalchemy_utils import JSONType, generic_relationship

from sqlalchemy_history.plugins.base import Plugin
from sqlalchemy_history.factory import ModelFactory
from sqlalchemy_history.plugins.base import Plugin
from sqlalchemy_history.utils import version_class, version_obj


Expand Down
4 changes: 2 additions & 2 deletions sqlalchemy_history/plugins/null_delete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from sqlalchemy_history.plugins.base import Plugin
from sqlalchemy_history.operation import Operation
from sqlalchemy_history.utils import versioned_column_properties, is_internal_column
from sqlalchemy_history.plugins.base import Plugin
from sqlalchemy_history.utils import is_internal_column, versioned_column_properties


class NullDeletePlugin(Plugin):
Expand Down
Loading
Loading