Skip to content
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

(Bad rebase) Fix issue #1318: Type (typehint) error for db.relationship #1319

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
91d3932
refactor docs (#1301)
yuxiaoy1 Jan 14, 2024
3ecd038
Fixing missing base class in reflection docs, adding to reflection te…
pamelafox Jan 15, 2024
fec440f
Fix repr and add tests (#1296)
pamelafox Jan 15, 2024
fda01e2
Bump the github-actions group with 3 updates
dependabot[bot] Sep 11, 2023
0925777
Bump the github-actions group with 1 update
dependabot[bot] Oct 1, 2023
6a52dec
Bump the python-requirements group in /requirements with 2 updates
dependabot[bot] Oct 1, 2023
b71eec9
[pre-commit.ci] pre-commit autoupdate (#1265)
pre-commit-ci[bot] Oct 3, 2023
7d7ba77
Bump urllib3 from 2.0.4 to 2.0.6 in /requirements (#1264)
dependabot[bot] Oct 3, 2023
55a8c0b
Bump urllib3 from 2.0.6 to 2.0.7 in /requirements (#1270)
dependabot[bot] Oct 18, 2023
9556d68
Bump the github-actions group with 2 updates
dependabot[bot] Nov 1, 2023
1413acc
Bump the python-requirements group in /requirements with 6 updates
dependabot[bot] Nov 1, 2023
6fb263c
Fix PR id in the changelog
heavelock Nov 5, 2023
71333de
Bump the github-actions group with 2 updates
dependabot[bot] Dec 1, 2023
5c982b4
Bump the python-requirements group in /requirements with 5 updates
dependabot[bot] Dec 1, 2023
eb838fe
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Dec 4, 2023
0fa0f07
[pre-commit.ci] pre-commit autoupdate (#1300)
pre-commit-ci[bot] Jan 15, 2024
ef0109f
Bump jinja2 from 3.1.2 to 3.1.3 in /requirements (#1304)
dependabot[bot] Jan 15, 2024
9d0a065
Bump the python-requirements group in /requirements with 6 updates (#…
dependabot[bot] Jan 15, 2024
ac14a38
Fix issue #1318
cainmagi Mar 26, 2024
5012474
Fix an issue when `tox p` fails because `mypy` is forbidden.
cainmagi Mar 26, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
lock:
runs-on: ubuntu-latest
steps:
- uses: dessant/lock-threads@be8aa5be94131386884a6da4189effda9b14aa21
- uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771
with:
issue-inactive-days: 14
pr-inactive-days: 14
10 changes: 5 additions & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ jobs:
outputs:
hash: ${{ steps.hash.outputs.hash }}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236
with:
python-version: '3.x'
cache: 'pip'
Expand All @@ -23,7 +23,7 @@ jobs:
- name: generate hash
id: hash
run: cd dist && echo "hash=$(sha256sum * | base64 -w0)" >> $GITHUB_OUTPUT
- uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce
- uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32
with:
path: ./dist
provenance:
Expand Down Expand Up @@ -63,10 +63,10 @@ jobs:
steps:
- uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a
# Try uploading to Test PyPI first, in case something fails.
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
- uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: artifact/
- uses: pypa/gh-action-pypi-publish@b7f401de30cb6434a1e19f805ff006643653240e
- uses: pypa/gh-action-pypi-publish@2f6f737ca5f74c637829c0f5c3acd0e29ea5e8bf
with:
packages-dir: artifact/
6 changes: 3 additions & 3 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ jobs:
- {name: '3.8', python: '3.8', tox: py38}
- {name: 'Typing', python: '3.11', tox: typing}
steps:
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744
- uses: actions/setup-python@61a6322f88396a6271a6ee3565807d608ecaddd1
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236
with:
python-version: ${{ matrix.python }}
cache: 'pip'
cache-dependency-path: 'requirements/*.txt'
- name: cache mypy
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
with:
path: ./.mypy_cache
key: mypy|${{ matrix.python }}|${{ hashFiles('requirements/mypy.txt') }}
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ ci:
autoupdate_schedule: monthly
repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py38-plus"]
- repo: https://github.com/asottile/reorder-python-imports
rev: v3.10.0
rev: v3.12.0
hooks:
- id: reorder-python-imports
files: "^(?!examples/)"
args: ["--py38-plus", "--application-directories", "src"]
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 23.12.1
hooks:
- id: black
args: ["--target-version", "py38"]
Expand All @@ -25,7 +25,7 @@ repos:
- flake8-bugbear
- flake8-implicit-str-concat
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: fix-byte-order-marker
- id: trailing-whitespace
Expand Down
8 changes: 7 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
Version 3.1.2
-------------

- Fix issue with calling ``repr()`` on ``SQLAlchemy`` instance with no default engine. :issue:`1295`


Version 3.1.1
-------------

Released 2023-09-11

- Deprecate the ``__version__`` attribute. Use feature detection, or
``importlib.metadata.version("flask-sqlalchemy")``, instead. :issue:`5230`
``importlib.metadata.version("flask-sqlalchemy")``, instead. :pr:`1256`


Version 3.1.0
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ A Simple Example
db = SQLAlchemy(app, model_class=Base)

class User(db.Model):
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)

with app.app_context():
db.create_all()
Expand Down
29 changes: 14 additions & 15 deletions docs/customizing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ joined-table inheritance.
db = SQLAlchemy(app, model_class=Base)

class User(db.Model):
name: Mapped[str] = mapped_column(String)
name: Mapped[str]

class Employee(User):
title: Mapped[str] = mapped_column(String)
title: Mapped[str]


Abstract Models and Mixins
Expand All @@ -52,34 +52,33 @@ they are created or updated.

.. code-block:: python

from datetime import datetime
from sqlalchemy import DateTime, Integer, String
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, declared_attr
from datetime import datetime, timezone
from sqlalchemy.orm import Mapped, mapped_column

class TimestampModel(db.Model):
__abstract__ = True
created: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
updated: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
created: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc))
updated: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))

class Author(db.Model):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
username: Mapped[str] = mapped_column(String, unique=True, nullable=False)
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)

class Post(TimestampModel):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
title: Mapped[str] = mapped_column(String, nullable=False)
id: Mapped[int] = mapped_column(primary_key=True)
title: Mapped[str]

This can also be done with a mixin class, inheriting from ``db.Model`` separately.

.. code-block:: python

class TimestampMixin:
created: Mapped[datetime] = mapped_column(DateTime, nullable=False, default=datetime.utcnow)
updated: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
created: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc))
updated: Mapped[datetime] = mapped_column(default=lambda: datetime.now(timezone.utc), onupdate=lambda: datetime.now(timezone.utc))

class Post(TimestampMixin, db.Model):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
title: Mapped[str] = mapped_column(String, nullable=False)
id: Mapped[int] = mapped_column(primary_key=True)
title: Mapped[str]


Disabling Table Name Generation
Expand Down
15 changes: 10 additions & 5 deletions docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ is not set and a primary key column is defined.
from sqlalchemy.orm import Mapped, mapped_column

class User(db.Model):
id: Mapped[int] = mapped_column(db.Integer, primary_key=True)
username: Mapped[str] = mapped_column(db.String, unique=True, nullable=False)
email: Mapped[str] = mapped_column(db.String)
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)
email: Mapped[str]


Defining a model does not create it in the database. Use :meth:`~.SQLAlchemy.create_all`
Expand Down Expand Up @@ -139,14 +139,19 @@ defining the full model.

Call the :meth:`~.SQLAlchemy.reflect` method on the extension. It will reflect all the
tables for each bind key. Each metadata's ``tables`` attribute will contain the detected
table objects.
table objects. See :doc:`binds` for more details on bind keys.

.. code-block:: python

with app.app_context():
db.reflect()

class User:
# From the default bind key
class Book(db.Model):
__table__ = db.metadata.tables["book"]

# From an "auth" bind key
class User(db.Model):
__table__ = db.metadatas["auth"].tables["user"]

In most cases, it will be more maintainable to define the model classes yourself. You
Expand Down
2 changes: 1 addition & 1 deletion docs/pagination.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ The following Jinja macro renders a simple pagination widget.
.. code-block:: jinja

{% macro render_pagination(pagination, endpoint) %}
<div class=page-items>
<div class="page-items">
{{ pagination.first }} - {{ pagination.last }} of {{ pagination.total }}
</div>
<div class=pagination>
Expand Down
6 changes: 3 additions & 3 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ The model will generate a table name by converting the ``CamelCase`` class name
from sqlalchemy.orm import Mapped, mapped_column

class User(db.Model):
id: Mapped[int] = mapped_column(Integer, primary_key=True)
username: Mapped[str] = mapped_column(String, unique=True, nullable=False)
email: Mapped[str] = mapped_column(String)
id: Mapped[int] = mapped_column(primary_key=True)
username: Mapped[str] = mapped_column(unique=True)
email: Mapped[str]


See :doc:`models` for more information about defining and creating models and tables.
Expand Down
28 changes: 14 additions & 14 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ alabaster==0.7.13
# via sphinx
babel==2.12.1
# via sphinx
blinker==1.6.2
blinker==1.7.0
# via -r tests.in
build==1.0.3
# via pip-tools
cachetools==5.3.1
cachetools==5.3.2
# via tox
certifi==2023.7.22
# via requests
Expand All @@ -34,7 +34,7 @@ distlib==0.3.7
# via virtualenv
docutils==0.20.1
# via sphinx
filelock==3.12.3
filelock==3.13.1
# via
# tox
# virtualenv
Expand All @@ -48,17 +48,17 @@ imagesize==1.4.1
# via sphinx
iniconfig==2.0.0
# via pytest
jinja2==3.1.2
jinja2==3.1.3
# via sphinx
markupsafe==2.1.3
# via jinja2
mypy==1.5.1
mypy==1.8.0
# via -r mypy.in
mypy-extensions==1.0.0
# via mypy
nodeenv==1.8.0
# via pre-commit
packaging==23.1
packaging==23.2
# via
# build
# pallets-sphinx-themes
Expand All @@ -70,23 +70,23 @@ pallets-sphinx-themes==2.1.1
# via -r docs.in
pip-tools==7.3.0
# via -r dev.in
platformdirs==3.10.0
platformdirs==4.1.0
# via
# tox
# virtualenv
pluggy==1.3.0
# via
# pytest
# tox
pre-commit==3.4.0
pre-commit==3.6.0
# via -r dev.in
pygments==2.16.1
# via sphinx
pyproject-api==1.6.1
# via tox
pyproject-hooks==1.0.0
# via build
pytest==7.4.2
pytest==7.4.4
# via
# -r mypy.in
# -r tests.in
Expand All @@ -99,7 +99,7 @@ requests==2.31.0
# via sphinx
snowballstemmer==2.2.0
# via sphinx
sphinx==7.2.5
sphinx==7.2.6
# via
# -r docs.in
# pallets-sphinx-themes
Expand All @@ -126,17 +126,17 @@ sphinxcontrib-qthelp==1.0.6
# via sphinx
sphinxcontrib-serializinghtml==1.1.9
# via sphinx
sqlalchemy==2.0.20
sqlalchemy==2.0.25
# via -r mypy.in
tox==4.11.3
tox==4.12.0
# via -r dev.in
typing-extensions==4.7.1
# via
# mypy
# sqlalchemy
urllib3==2.0.4
urllib3==2.0.7
# via requests
virtualenv==20.24.5
virtualenv==20.25.0
# via
# pre-commit
# tox
Expand Down
6 changes: 3 additions & 3 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
jinja2==3.1.2
jinja2==3.1.3
# via sphinx
markupsafe==2.1.3
# via jinja2
Expand All @@ -34,7 +34,7 @@ requests==2.31.0
# via sphinx
snowballstemmer==2.2.0
# via sphinx
sphinx==7.2.5
sphinx==7.2.6
# via
# -r docs.in
# pallets-sphinx-themes
Expand All @@ -61,5 +61,5 @@ sphinxcontrib-qthelp==1.0.6
# via sphinx
sphinxcontrib-serializinghtml==1.1.9
# via sphinx
urllib3==2.0.4
urllib3==2.0.7
# via requests
6 changes: 3 additions & 3 deletions requirements/mypy.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ greenlet==2.0.2
# via sqlalchemy
iniconfig==2.0.0
# via pytest
mypy==1.5.1
mypy==1.8.0
# via -r mypy.in
mypy-extensions==1.0.0
# via mypy
packaging==23.1
# via pytest
pluggy==1.3.0
# via pytest
pytest==7.4.2
pytest==7.4.4
# via -r mypy.in
sqlalchemy==2.0.20
sqlalchemy==2.0.25
# via -r mypy.in
typing-extensions==4.7.1
# via
Expand Down
Loading
Loading