Skip to content

Commit 8c815ee

Browse files
pre-commit-ci[bot]sheinbergon
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 0f4b6c8 commit 8c815ee

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/sqlacodegen/generators.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,10 @@ def remove_table_from_metadata(self, table: Table) -> None:
782782
for fk in list(other_table.foreign_keys):
783783
if fk.column.table.name == table.name:
784784
for constraint in list(other_table.constraints):
785-
if isinstance(constraint, ForeignKeyConstraint) and fk in constraint.elements:
785+
if (
786+
isinstance(constraint, ForeignKeyConstraint)
787+
and fk in constraint.elements
788+
):
786789
other_table.constraints.discard(constraint)
787790
fk.parent.foreign_keys.discard(fk)
788791
fks_to_remove.append(fk)
@@ -813,8 +816,13 @@ def generate_models(self) -> list[Model]:
813816
# them normally
814817
links: defaultdict[str, list[Model]] = defaultdict(lambda: [])
815818
for table in self.metadata.sorted_tables:
816-
if not table.primary_key and not self.generate_tables_for_relations_without_pk:
817-
self.warnings.append(f"table {table.name!r} has no primary key and will not be included in the generated models")
819+
if (
820+
not table.primary_key
821+
and not self.generate_tables_for_relations_without_pk
822+
):
823+
self.warnings.append(
824+
f"table {table.name!r} has no primary key and will not be included in the generated models"
825+
)
818826
self.remove_table_from_metadata(table)
819827
continue
820828

tests/test_generator_sqlmodel.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,7 @@ class TestTableWithPkey(SQLModel, table=True):
210210
""",
211211
)
212212
assert len(generator.warnings) == 1
213-
assert generator.warnings[0] == "table 'test_table' has no primary key and will not be included in the generated models"
213+
assert (
214+
generator.warnings[0]
215+
== "table 'test_table' has no primary key and will not be included in the generated models"
216+
)

0 commit comments

Comments
 (0)