Skip to content

Commit c07aa67

Browse files
committed
Fixed KeyError when rendering an empty index
Fixes #192.
1 parent 08fb63d commit c07aa67

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Version history
44
**UNRELEASED**
55

66
- Migrated all packaging/testing configuration to ``pyproject.toml``
7+
. Fixed ``KeyError`` when rendering an index without any columns
78

89
**3.0.0b3**
910

src/sqlacodegen/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ def uses_default_name(constraint: Constraint | Index) -> bool:
127127

128128
try:
129129
convention: str = table.metadata.naming_convention[key]
130+
return constraint.name == (convention % values)
130131
except KeyError:
131132
return False
132133

133-
return constraint.name == (convention % values)
134-
135134

136135
def render_callable(
137136
name: str,

tests/test_generators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ def test_indexes(self, generator: CodeGenerator) -> None:
300300
Column("id", INTEGER),
301301
Column("number", INTEGER),
302302
Column("text", VARCHAR),
303+
Index("ix_empty"),
303304
)
304305
simple_items.indexes.add(Index("ix_number", simple_items.c.number))
305306
simple_items.indexes.add(
@@ -325,6 +326,7 @@ def test_indexes(self, generator: CodeGenerator) -> None:
325326
Column('id', Integer),
326327
Column('number', Integer, index=True),
327328
Column('text', String, unique=True),
329+
Index('ix_empty'),
328330
Index('ix_text_number', 'text', 'number', unique=True)
329331
)
330332
""",

0 commit comments

Comments
 (0)