sqlacodegen 4.0.3__tar.gz → 4.0.4__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.
Files changed (37) hide show
  1. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/workflows/publish.yml +2 -2
  2. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.pre-commit-config.yaml +2 -2
  3. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/CHANGES.rst +10 -0
  4. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/PKG-INFO +1 -1
  5. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/generators.py +11 -0
  6. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/PKG-INFO +1 -1
  7. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/test_generator_declarative.py +26 -0
  8. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/test_generator_tables.py +32 -1
  9. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/FUNDING.yml +0 -0
  10. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
  11. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  12. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/ISSUE_TEMPLATE/features_request.yaml +0 -0
  13. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/dependabot.yml +0 -0
  14. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/pull_request_template.md +0 -0
  15. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.github/workflows/test.yml +0 -0
  16. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/.gitignore +0 -0
  17. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/CONTRIBUTING.rst +0 -0
  18. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/LICENSE +0 -0
  19. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/README.rst +0 -0
  20. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/pyproject.toml +0 -0
  21. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/setup.cfg +0 -0
  22. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/__init__.py +0 -0
  23. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/__main__.py +0 -0
  24. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/cli.py +0 -0
  25. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/models.py +0 -0
  26. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/py.typed +0 -0
  27. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen/utils.py +0 -0
  28. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/SOURCES.txt +0 -0
  29. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/dependency_links.txt +0 -0
  30. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/entry_points.txt +0 -0
  31. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/requires.txt +0 -0
  32. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/src/sqlacodegen.egg-info/top_level.txt +0 -0
  33. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/__init__.py +0 -0
  34. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/conftest.py +0 -0
  35. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/test_cli.py +0 -0
  36. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/test_generator_dataclass.py +0 -0
  37. {sqlacodegen-4.0.3 → sqlacodegen-4.0.4}/tests/test_generator_sqlmodel.py +0 -0
@@ -24,7 +24,7 @@ jobs:
24
24
  - name: Create packages
25
25
  run: python -m build
26
26
  - name: Archive packages
27
- uses: actions/upload-artifact@v6
27
+ uses: actions/upload-artifact@v7
28
28
  with:
29
29
  name: dist
30
30
  path: dist
@@ -38,7 +38,7 @@ jobs:
38
38
  id-token: write
39
39
  steps:
40
40
  - name: Retrieve packages
41
- uses: actions/download-artifact@v7
41
+ uses: actions/download-artifact@v8
42
42
  with:
43
43
  name: dist
44
44
  path: dist
@@ -16,14 +16,14 @@ repos:
16
16
  - id: trailing-whitespace
17
17
 
18
18
  - repo: https://github.com/astral-sh/ruff-pre-commit
19
- rev: v0.14.10
19
+ rev: v0.15.9
20
20
  hooks:
21
21
  - id: ruff
22
22
  args: [--fix, --show-fixes]
23
23
  - id: ruff-format
24
24
 
25
25
  - repo: https://github.com/pre-commit/mirrors-mypy
26
- rev: v1.19.1
26
+ rev: v1.20.0
27
27
  hooks:
28
28
  - id: mypy
29
29
  additional_dependencies:
@@ -1,6 +1,16 @@
1
1
  Version history
2
2
  ===============
3
3
 
4
+ **4.0.4*
5
+
6
+ - Added autoincrement to primary key columns to prevent missing field errors.
7
+ (`#473 <https://github.com/agronholm/sqlacodegen/issues/473>`_; PR by @jtmonroe)
8
+ - Preserve dialect-specific ``ARRAY`` types (e.g. ``postgresql.ARRAY``) instead
9
+ of adapting them to the generic ``sqlalchemy.ARRAY``. The generic type does
10
+ not implement operators like ``.contains()``, so adapting silently broke
11
+ PostgreSQL array queries on generated models.
12
+ (`#441 <https://github.com/agronholm/sqlacodegen/issues/441>`_)
13
+
4
14
  **4.0.3**
5
15
 
6
16
  - Improved rendering of ``Identity`` server defaults by explicitly rendering
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlacodegen
3
- Version: 4.0.3
3
+ Version: 4.0.4
4
4
  Summary: Automatic model code generator for SQLAlchemy
5
5
  Author-email: Alex Grönholm <alex.gronholm@nextday.fi>
6
6
  Maintainer-email: Idan Sheinberg <ishinberg0@gmail.com>
@@ -471,6 +471,9 @@ class TablesGenerator(CodeGenerator):
471
471
  )
472
472
  or column.primary_key
473
473
  )
474
+ is_autoincrement = (
475
+ isinstance(column.autoincrement, bool) and column.autoincrement
476
+ )
474
477
  has_index = any(
475
478
  set(i.columns) == {column} and uses_default_name(i)
476
479
  for i in column.table.indexes
@@ -494,6 +497,8 @@ class TablesGenerator(CodeGenerator):
494
497
  kwargs["key"] = column.key
495
498
  if is_primary:
496
499
  kwargs["primary_key"] = True
500
+ if is_autoincrement and is_primary:
501
+ kwargs["autoincrement"] = True
497
502
  if not column.nullable and not column.primary_key:
498
503
  kwargs["nullable"] = False
499
504
  if column.nullable and is_part_of_composite_pk:
@@ -1031,6 +1036,12 @@ class TablesGenerator(CodeGenerator):
1031
1036
  column.server_default = None
1032
1037
 
1033
1038
  def get_adapted_type(self, coltype: Any) -> Any:
1039
+ # Keep dialect-specific ARRAY subclasses; the generic sqlalchemy.ARRAY
1040
+ # is missing operators like .contains() (GH-441).
1041
+ if isinstance(coltype, ARRAY) and type(coltype) is not ARRAY:
1042
+ coltype.item_type = self.get_adapted_type(coltype.item_type)
1043
+ return coltype
1044
+
1034
1045
  compiled_type = coltype.compile(self.bind.engine.dialect)
1035
1046
  for supercls in coltype.__class__.__mro__:
1036
1047
  if not supercls.__name__.startswith("_") and hasattr(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sqlacodegen
3
- Version: 4.0.3
3
+ Version: 4.0.4
4
4
  Summary: Automatic model code generator for SQLAlchemy
5
5
  Author-email: Alex Grönholm <alex.gronholm@nextday.fi>
6
6
  Maintainer-email: Idan Sheinberg <ishinberg0@gmail.com>
@@ -1497,6 +1497,32 @@ class SimpleItems(Base):
1497
1497
  )
1498
1498
 
1499
1499
 
1500
+ def test_composite_autoincrement_pk(generator: CodeGenerator) -> None:
1501
+ Table(
1502
+ "simple_autoincrement_items",
1503
+ generator.metadata,
1504
+ Column("id1", INTEGER, primary_key=True, autoincrement=True),
1505
+ Column("id2", INTEGER, primary_key=True),
1506
+ )
1507
+ validate_code(
1508
+ generator.generate(),
1509
+ """\
1510
+ from sqlalchemy import Integer
1511
+ from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
1512
+
1513
+ class Base(DeclarativeBase):
1514
+ pass
1515
+
1516
+
1517
+ class SimpleAutoincrementItems(Base):
1518
+ __tablename__ = 'simple_autoincrement_items'
1519
+
1520
+ id1: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
1521
+ id2: Mapped[int] = mapped_column(Integer, primary_key=True)
1522
+ """,
1523
+ )
1524
+
1525
+
1500
1526
  def test_joined_inheritance(generator: CodeGenerator) -> None:
1501
1527
  Table(
1502
1528
  "simple_sub_items",
@@ -130,7 +130,8 @@ def test_arrays(generator: CodeGenerator) -> None:
130
130
  validate_code(
131
131
  generator.generate(),
132
132
  """\
133
- from sqlalchemy import ARRAY, Column, Double, Integer, MetaData, Table
133
+ from sqlalchemy import Column, Double, Integer, MetaData, Table
134
+ from sqlalchemy.dialects.postgresql import ARRAY
134
135
 
135
136
  metadata = MetaData()
136
137
 
@@ -144,6 +145,36 @@ def test_arrays(generator: CodeGenerator) -> None:
144
145
  )
145
146
 
146
147
 
148
+ @pytest.mark.parametrize("engine", ["postgresql"], indirect=["engine"])
149
+ def test_array_preserves_dialect_for_runtime_operators(
150
+ generator: CodeGenerator,
151
+ ) -> None:
152
+ """Regression test for GH-441."""
153
+ Table(
154
+ "simple_items",
155
+ generator.metadata,
156
+ Column("id", postgresql.TEXT, primary_key=True),
157
+ Column("tags", postgresql.ARRAY(postgresql.TEXT)),
158
+ )
159
+
160
+ validate_code(
161
+ generator.generate(),
162
+ """\
163
+ from sqlalchemy import Column, MetaData, Table, Text
164
+ from sqlalchemy.dialects.postgresql import ARRAY
165
+
166
+ metadata = MetaData()
167
+
168
+
169
+ t_simple_items = Table(
170
+ 'simple_items', metadata,
171
+ Column('id', Text, primary_key=True),
172
+ Column('tags', ARRAY(Text()))
173
+ )
174
+ """,
175
+ )
176
+
177
+
147
178
  @pytest.mark.parametrize("engine", ["postgresql"], indirect=["engine"])
148
179
  def test_jsonb(generator: CodeGenerator) -> None:
149
180
  Table(
File without changes
File without changes
File without changes
File without changes
File without changes