Skip to content

Commit

Permalink
Dialect: Fix get_pk_constraint to return list instead of set type
Browse files Browse the repository at this point in the history
The test suite of `meltano-tap-cratedb`, derived from the corresponding
PostgreSQL adapter, will process database introspection return values by
marshalling them to JSON. Because `get_pk_constraint` returns a `set`
type, that will fail.

    TypeError: Object of type set is not JSON serializable
  • Loading branch information
amotl committed Jun 24, 2024
1 parent 9a95be0 commit 37d1521
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Added/reactivated documentation as `sqlalchemy-cratedb`
- Added `CrateIdentifierPreparer`, in order to quote reserved words
like `object` properly, for example when used as column names.
- Fixed `CrateDialect.get_pk_constraint` to return `list` instead of `set` type

## 2024/06/13 0.37.0
- Added support for CrateDB's [FLOAT_VECTOR] data type and its accompanying
Expand Down
2 changes: 1 addition & 1 deletion src/sqlalchemy_cratedb/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def result_fun(result):
(table_name, schema or self.default_schema_name)
)
pks = result_fun(pk_result)
return {'constrained_columns': pks,
return {'constrained_columns': list(sorted(pks)),
'name': 'PRIMARY KEY'}

@reflection.cache
Expand Down
4 changes: 2 additions & 2 deletions tests/dialect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def test_primary_keys_2_3_0(self):
)
self.fake_cursor.fetchall = MagicMock(return_value=[["id"], ["id2"], ["id3"]])

eq_(insp.get_pk_constraint("characters")['constrained_columns'], {"id", "id2", "id3"})
eq_(insp.get_pk_constraint("characters")['constrained_columns'], ["id", "id2", "id3"])
self.fake_cursor.fetchall.assert_called_once_with()
in_("information_schema.key_column_usage", self.executed_statement)
in_("table_catalog = ?", self.executed_statement)
Expand All @@ -103,7 +103,7 @@ def test_primary_keys_3_0_0(self):
)
self.fake_cursor.fetchall = MagicMock(return_value=[["id"], ["id2"], ["id3"]])

eq_(insp.get_pk_constraint("characters")['constrained_columns'], {"id", "id2", "id3"})
eq_(insp.get_pk_constraint("characters")['constrained_columns'], ["id", "id2", "id3"])
self.fake_cursor.fetchall.assert_called_once_with()
in_("information_schema.key_column_usage", self.executed_statement)
in_("table_schema = ?", self.executed_statement)
Expand Down

0 comments on commit 37d1521

Please sign in to comment.