Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
3 changes: 3 additions & 0 deletions src/sqlalchemy_cratedb/support/polyfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_support_polyfill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand Down