Skip to content
Open
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
56 changes: 23 additions & 33 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,30 @@ jobs:

strategy:
matrix:
python-version: [ '3.9', '3.11', '3.13' ]
sqlalchemy-version: [ '1.4' ]
include:
- sqlalchemy-version: '1.4'
sqlalchemy-lt-version: '2.0'
flask-sqlalchemy-version: '3.0'
flask-sqlalchemy-lt-version: '3.1'
flask-version: '2.2'
flask-lt-version: '4.0'
python-version: ["3.9", "3.11", "3.13"]
sqlalchemy-version: ["2.0"]

name: Python ${{ matrix.python-version }} - SQLAlchemy ${{ matrix.sqlalchemy-version }}

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[tests] pytest-cov \
"sqlalchemy>=${{ matrix.sqlalchemy-version }},<${{ matrix.sqlalchemy-lt-version }}" \
"flask-sqlalchemy>=${{ matrix.flask-sqlalchemy-version }},<${{ matrix.flask-sqlalchemy-lt-version }}" \
"flask>=${{ matrix.flask-version }},<${{ matrix.flask-lt-version }}"

- name: Test with pytest
run: |
pytest -v --cov --cov-report xml

- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.11' && matrix.sqlalchemy-version == '1.4'}}
uses: codecov/codecov-action@v3
with:
flags: pytest
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -e .[tests] pytest-cov

- name: Test with pytest
run: |
pytest -v --cov --cov-report xml

- name: Upload coverage to Codecov
if: ${{ matrix.python-version == '3.11' && matrix.sqlalchemy-version == '1.4'}}
uses: codecov/codecov-action@v3
with:
flags: pytest
2 changes: 1 addition & 1 deletion requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ flask-sqlalchemy
flask-migrate
marshmallow
python-dateutil
sqlalchemy<2
sqlalchemy<3
7 changes: 4 additions & 3 deletions src/utils_flask_sqla/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def box_drowing(up, down, left, right, bold=True):
@click.option("--json", "json_output", is_flag=True, help="Output commands results as JSON.")
@with_appcontext
def exec(command, commit, json_output):
db = current_app.extensions["sqlalchemy"].db
db = current_app.extensions["sqlalchemy"]
results = []
for cmd in command:
results.append(db.session.execute(cmd))
Expand Down Expand Up @@ -86,7 +86,7 @@ def exec(command, commit, json_output):
@with_appcontext
def autoupgrade(directory, sql, tag, x_arg):
"""Upgrade all branches to head."""
db = current_app.extensions["sqlalchemy"].db
db = current_app.extensions["sqlalchemy"]
migrate = current_app.extensions["migrate"].migrate
config = migrate.get_config(directory, x_arg)
script = ScriptDirectory.from_config(config)
Expand Down Expand Up @@ -117,7 +117,8 @@ def autoupgrade(directory, sql, tag, x_arg):
@with_appcontext
def status(directory, x_arg, show_dependencies, branches):
"""Show all revisions sorted by branches."""
db = current_app.extensions["sqlalchemy"].db
db = current_app.extensions["sqlalchemy"]

migrate = current_app.extensions["migrate"].migrate

config = migrate.get_config(directory, x_arg)
Expand Down
5 changes: 4 additions & 1 deletion src/utils_flask_sqla/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

from sqlalchemy.orm import ColumnProperty
from sqlalchemy import inspect
from sqlalchemy.ext.hybrid import hybrid_property, HYBRID_PROPERTY
from sqlalchemy.ext.hybrid import hybrid_property
from sqlalchemy.ext.hybrid import HybridExtensionType
from sqlalchemy.types import DateTime, Date, Time
from sqlalchemy.dialects.postgresql.base import UUID

Expand All @@ -28,6 +29,8 @@
"numeric": lambda x: str(x) if x else None,
}

HYBRID_PROPERTY = HybridExtensionType.HYBRID_PROPERTY


def get_serializer(col):
if isinstance(col, ColumnProperty):
Expand Down
19 changes: 18 additions & 1 deletion src/utils_flask_sqla/tests/test_temporary_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@
import pytest
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import sessionmaker

db = SQLAlchemy()
Session = sessionmaker()

from flask_sqlalchemy.session import Session as FSASession


class TestSession(FSASession):
join_transaction_mode = "create_savepoint"
expire_on_commit = False

def commit(self):
if self.in_nested_transaction():
self.flush()
else:
super().commit()


db = SQLAlchemy(session_options={"class_": TestSession})


class MyModel(db.Model):
Expand Down
Loading