sqlacodegen 4.0.2__tar.gz → 4.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/CHANGES.rst +6 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/PKG-INFO +1 -1
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/generators.py +24 -1
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/PKG-INFO +1 -1
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/test_generator_tables.py +35 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/FUNDING.yml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/ISSUE_TEMPLATE/features_request.yaml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/dependabot.yml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/pull_request_template.md +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/workflows/publish.yml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.github/workflows/test.yml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.gitignore +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/.pre-commit-config.yaml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/CONTRIBUTING.rst +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/LICENSE +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/README.rst +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/pyproject.toml +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/setup.cfg +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/__init__.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/__main__.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/cli.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/models.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/py.typed +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen/utils.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/SOURCES.txt +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/dependency_links.txt +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/entry_points.txt +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/requires.txt +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/src/sqlacodegen.egg-info/top_level.txt +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/__init__.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/conftest.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/test_cli.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/test_generator_dataclass.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/test_generator_declarative.py +0 -0
- {sqlacodegen-4.0.2 → sqlacodegen-4.0.3}/tests/test_generator_sqlmodel.py +0 -0
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
Version history
|
|
2
2
|
===============
|
|
3
3
|
|
|
4
|
+
**4.0.3**
|
|
5
|
+
|
|
6
|
+
- Improved rendering of ``Identity`` server defaults by explicitly rendering
|
|
7
|
+
non-default parameters; ``Decimal`` values (as returned by some databases) are
|
|
8
|
+
now cast to ``int`` (PR by @NotCarlosSerrano)
|
|
9
|
+
|
|
4
10
|
**4.0.2**
|
|
5
11
|
|
|
6
12
|
- Fixed rendering of inherited keyword arguments for dialect-specific types that use
|
|
@@ -7,6 +7,7 @@ from abc import ABCMeta, abstractmethod
|
|
|
7
7
|
from collections import defaultdict
|
|
8
8
|
from collections.abc import Collection, Iterable, Mapping, Sequence
|
|
9
9
|
from dataclasses import dataclass
|
|
10
|
+
from decimal import Decimal
|
|
10
11
|
from importlib import import_module
|
|
11
12
|
from inspect import Parameter
|
|
12
13
|
from itertools import count
|
|
@@ -521,7 +522,29 @@ class TablesGenerator(CodeGenerator):
|
|
|
521
522
|
render_callable("Computed", repr(expression), kwargs=computed_kwargs)
|
|
522
523
|
)
|
|
523
524
|
elif isinstance(column.server_default, Identity):
|
|
524
|
-
|
|
525
|
+
identity = column.server_default
|
|
526
|
+
identity_kwargs: dict[str, Any] = {}
|
|
527
|
+
|
|
528
|
+
for name, param in inspect.signature(Identity).parameters.items():
|
|
529
|
+
if name == "self" or param.kind in (
|
|
530
|
+
Parameter.VAR_POSITIONAL,
|
|
531
|
+
Parameter.VAR_KEYWORD,
|
|
532
|
+
):
|
|
533
|
+
continue
|
|
534
|
+
|
|
535
|
+
value = getattr(identity, name, None)
|
|
536
|
+
if value is None:
|
|
537
|
+
continue
|
|
538
|
+
|
|
539
|
+
if isinstance(value, Decimal):
|
|
540
|
+
value = int(value)
|
|
541
|
+
|
|
542
|
+
if param.default is not Parameter.empty and value == param.default:
|
|
543
|
+
continue
|
|
544
|
+
|
|
545
|
+
identity_kwargs[name] = value
|
|
546
|
+
|
|
547
|
+
args.append(render_callable("Identity", kwargs=identity_kwargs))
|
|
525
548
|
elif column.server_default:
|
|
526
549
|
kwargs["server_default"] = repr(column.server_default)
|
|
527
550
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
+
from decimal import Decimal
|
|
3
4
|
from textwrap import dedent
|
|
4
5
|
|
|
5
6
|
import pytest
|
|
@@ -1217,6 +1218,40 @@ def test_identity_column(generator: CodeGenerator) -> None:
|
|
|
1217
1218
|
)
|
|
1218
1219
|
|
|
1219
1220
|
|
|
1221
|
+
def test_identity_column_decimal_values(generator: CodeGenerator) -> None:
|
|
1222
|
+
# MSSQL reflects Identity column parameters (start, increment) as Decimal
|
|
1223
|
+
# values instead of integers. This test ensures those are serialized correctly.
|
|
1224
|
+
identity = Identity(start=1, increment=2)
|
|
1225
|
+
# Simulate database reflection returning Decimal values (as MSSQL does)
|
|
1226
|
+
identity.start = Decimal("1") # type: ignore[assignment]
|
|
1227
|
+
identity.increment = Decimal("2") # type: ignore[assignment]
|
|
1228
|
+
Table(
|
|
1229
|
+
"simple_items",
|
|
1230
|
+
generator.metadata,
|
|
1231
|
+
Column(
|
|
1232
|
+
"id",
|
|
1233
|
+
INTEGER,
|
|
1234
|
+
primary_key=True,
|
|
1235
|
+
server_default=identity,
|
|
1236
|
+
),
|
|
1237
|
+
)
|
|
1238
|
+
|
|
1239
|
+
validate_code(
|
|
1240
|
+
generator.generate(),
|
|
1241
|
+
"""\
|
|
1242
|
+
from sqlalchemy import Column, Identity, Integer, MetaData, Table
|
|
1243
|
+
|
|
1244
|
+
metadata = MetaData()
|
|
1245
|
+
|
|
1246
|
+
|
|
1247
|
+
t_simple_items = Table(
|
|
1248
|
+
'simple_items', metadata,
|
|
1249
|
+
Column('id', Integer, Identity(start=1, increment=2), primary_key=True)
|
|
1250
|
+
)
|
|
1251
|
+
""",
|
|
1252
|
+
)
|
|
1253
|
+
|
|
1254
|
+
|
|
1220
1255
|
def test_multiline_column_comment(generator: CodeGenerator) -> None:
|
|
1221
1256
|
Table(
|
|
1222
1257
|
"simple_items",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|