diff --git a/backlog.md b/backlog.md index 44905915..46bfbcfc 100644 --- a/backlog.md +++ b/backlog.md @@ -21,3 +21,5 @@ From dialect split-off. - https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Connection.execution_options.params.stream_results - https://docs.sqlalchemy.org/en/20/core/connections.html#sqlalchemy.engine.Result.yield_per - https://github.com/jamescasbon/vertica-sqlalchemy +- pandas: `index=True` +- @cratedb: test_table_kwargs_unknown => ColumnUnknownException[Column bazqux unknown] diff --git a/src/sqlalchemy_cratedb/support/polyfill.py b/src/sqlalchemy_cratedb/support/polyfill.py index 22dad7ce..08f2ff2e 100644 --- a/src/sqlalchemy_cratedb/support/polyfill.py +++ b/src/sqlalchemy_cratedb/support/polyfill.py @@ -39,7 +39,10 @@ def check_uniqueness_factory(sa_entity, *attribute_names): This is used by CrateDB's MLflow adapter. + TODO: Maybe add to some helper function? TODO: Maybe enable through a dialect parameter `crate_polyfill_unique` or such. + TODO: Maybe derive from the model definition itself? + __table_args__ = (sa.UniqueConstraint("name", "user_id", name="unique_name_user"),) """ # noqa: E501 # Synthesize a canonical "name" for the constraint, diff --git a/tests/test_support_polyfill.py b/tests/test_support_polyfill.py index 181456ae..56bc89cd 100644 --- a/tests/test_support_polyfill.py +++ b/tests/test_support_polyfill.py @@ -84,7 +84,7 @@ class FooBar(Base): name = sa.Column(sa.String) # Add synthetic UNIQUE constraint on `name` column. - listen(FooBar, "before_insert", check_uniqueness_factory(FooBar, "name")) + listen(FooBar, "before_insert", check_uniqueness_factory(FooBar, "id", "name")) Base.metadata.drop_all(engine, checkfirst=True) Base.metadata.create_all(engine, checkfirst=True) @@ -96,11 +96,11 @@ class FooBar(Base): session.execute(sa.text("REFRESH TABLE foobar")) # Insert second record, violating the uniqueness constraint. - bar_item = FooBar(id="bar", name="foo") + bar_item = FooBar(id="foo", name="foo") session.add(bar_item) with pytest.raises(IntegrityError) as ex: session.commit() - assert ex.match("DuplicateKeyException in table 'foobar' on constraint 'name'") + assert ex.match("DuplicateKeyException in table 'foobar' on constraint 'id-name'") @pytest.mark.skipif(