Skip to content

Commit 43ee420

Browse files
committed
Add check for unknown types that have a size
1 parent 9af5a99 commit 43ee420

File tree

5 files changed

+16
-3
lines changed

5 files changed

+16
-3
lines changed

sqlsynthgen/make.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ def _get_provider_for_column(column: Column) -> Tuple[list[str], str, list[str]]
255255
column_type,
256256
column.name,
257257
)
258-
if column_size:
258+
elif column_size:
259259
generator_arguments.append(str(column_size))
260260

261261
return variable_names, generator_function, generator_arguments

tests/examples/example_orm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
UniqueConstraint,
1919
Uuid,
2020
)
21-
from sqlalchemy.dialects.postgresql import CIDR
21+
from sqlalchemy.dialects.postgresql import BIT, CIDR
2222
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
2323
import datetime
2424

@@ -78,6 +78,7 @@ class StrangeTypeTable(Base):
7878

7979
id: Mapped[int] = mapped_column(Integer, primary_key=True)
8080
column_with_unusual_type: Mapped[Optional[Any]] = mapped_column(CIDR)
81+
column_with_unusual_type_and_length: Mapped[Optional[Any]] = mapped_column(BIT(3))
8182

8283

8384
class UnignorableTable(Base):

tests/examples/expected_ssg.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(self):
9999
def __call__(self, dst_db_conn):
100100
result = {}
101101
result["column_with_unusual_type"] = generic.null_provider.null()
102+
result["column_with_unusual_type_and_length"] = generic.null_provider.null()
102103
return result
103104

104105

tests/examples/src.dump

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ ALTER TABLE public.table_to_be_ignored OWNER TO postgres;
224224

225225
CREATE TABLE public.strange_type_table (
226226
id integer NOT NULL,
227-
column_with_unusual_type cidr
227+
column_with_unusual_type cidr,
228+
column_with_unusual_type_and_length bit(3)
228229
);
229230

230231
ALTER TABLE public.strange_type_table OWNER TO postgres;

tests/test_functional.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ def test_workflow_minimal_args(self) -> None:
108108
"for column column_with_unusual_type. "
109109
"Setting this column to NULL always, "
110110
"you may want to configure a row generator for it instead.\n"
111+
"Unsupported SQLAlchemy type "
112+
"<class 'sqlalchemy.dialects.postgresql.types.BIT'> "
113+
"for column column_with_unusual_type_and_length. "
114+
"Setting this column to NULL always, "
115+
"you may want to configure a row generator for it instead.\n"
111116
"A unique constraint (ab_uniq) isn't fully covered by one "
112117
"row generator (['a']). Enforcement of the constraint may not work.\n"
113118
"A unique constraint (ab_uniq) isn't fully covered by one "
@@ -267,6 +272,11 @@ def test_workflow_maximal_args(self) -> None:
267272
"<class 'sqlalchemy.dialects.postgresql.types.CIDR'> "
268273
"for column column_with_unusual_type. "
269274
"Setting this column to NULL always, "
275+
"you may want to configure a row generator for it instead.\n"
276+
"Unsupported SQLAlchemy type "
277+
"<class 'sqlalchemy.dialects.postgresql.types.BIT'> "
278+
"for column column_with_unusual_type_and_length. "
279+
"Setting this column to NULL always, "
270280
"you may want to configure a row generator for it instead.\n",
271281
completed_process.stderr.decode("utf-8"),
272282
)

0 commit comments

Comments
 (0)