From de1547cf037b190cde497b15db6078c580f06c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 29 Aug 2022 11:34:56 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Update=20expresion.py,?= =?UTF-8?q?=20sync=20from=20Jinja2=20template?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqlmodel/sql/expression.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sqlmodel/sql/expression.py b/sqlmodel/sql/expression.py index e7317bcdd8..31c0bc1a1e 100644 --- a/sqlmodel/sql/expression.py +++ b/sqlmodel/sql/expression.py @@ -29,14 +29,14 @@ if sys.version_info.minor >= 7: class Select(_Select, Generic[_TSelect]): - pass + inherit_cache = True # This is not comparable to sqlalchemy.sql.selectable.ScalarSelect, that has a different # purpose. This is the same as a normal SQLAlchemy Select class where there's only one # entity, so the result will be converted to a scalar by default. This way writing # for loops on the results will feel natural. class SelectOfScalar(_Select, Generic[_TSelect]): - pass + inherit_cache = True else: from typing import GenericMeta # type: ignore @@ -45,10 +45,10 @@ class GenericSelectMeta(GenericMeta, _Select.__class__): # type: ignore pass class _Py36Select(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): - pass + inherit_cache = True class _Py36SelectOfScalar(_Select, Generic[_TSelect], metaclass=GenericSelectMeta): - pass + inherit_cache = True # Cast them for editors to work correctly, from several tricks tried, this works # for both VS Code and PyCharm From 08b8ac8360a0a73c8389521512b57a09ecdc33b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 29 Aug 2022 11:35:40 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20Add=20test=20to=20check=20that?= =?UTF-8?q?=20expresion.py=20is=20in=20sync=20with=20Jinja2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/generate_select.py | 8 ++++++++ scripts/test.sh | 1 + 2 files changed, 9 insertions(+) diff --git a/scripts/generate_select.py b/scripts/generate_select.py index b66a1673c4..f8aa30023f 100644 --- a/scripts/generate_select.py +++ b/scripts/generate_select.py @@ -1,3 +1,4 @@ +import os from itertools import product from pathlib import Path from typing import List, Tuple @@ -52,4 +53,11 @@ class Arg(BaseModel): result = black.format_str(result, mode=black.Mode()) +current_content = destiny_path.read_text() + +if current_content != result and os.getenv("CHECK_JINJA"): + raise RuntimeError( + "sqlmodel/sql/expression.py content not update with Jinja2 template" + ) + destiny_path.write_text(result) diff --git a/scripts/test.sh b/scripts/test.sh index 7fce865bd6..1887dc9949 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,6 +3,7 @@ set -e set -x +CHECK_JINJA=1 python scripts/generate_select.py coverage run -m pytest tests coverage combine coverage report --show-missing From 26377a264e51e94d880946abcd2cc8034b1474f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 29 Aug 2022 11:39:00 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=92=9A=20Fix=20CI=20for=20Python=203.?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/lint.sh | 2 ++ scripts/test.sh | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/lint.sh b/scripts/lint.sh index 4191d90f1f..02568cda6b 100755 --- a/scripts/lint.sh +++ b/scripts/lint.sh @@ -7,3 +7,5 @@ mypy sqlmodel flake8 sqlmodel tests docs_src black sqlmodel tests docs_src --check isort sqlmodel tests docs_src scripts --check-only +# TODO: move this to test.sh after deprecating Python 3.6 +CHECK_JINJA=1 python scripts/generate_select.py diff --git a/scripts/test.sh b/scripts/test.sh index 1887dc9949..7fce865bd6 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -3,7 +3,6 @@ set -e set -x -CHECK_JINJA=1 python scripts/generate_select.py coverage run -m pytest tests coverage combine coverage report --show-missing