Skip to content

Commit

Permalink
Fix: Return a list instead of a set from get_pk_constraint
Browse files Browse the repository at this point in the history
This is to fix the Apache Superset bug, that doesn't show the CrateDB
table metadata in the SQL Lab editor.
  • Loading branch information
Aymaru authored and amotl committed Jun 20, 2022
1 parent fc38073 commit a1df740
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changes for crate
Unreleased
==========

- Improve compatibility with Apache Superset by returning a list instead of a
set from ``get_pk_constraint``. Otherwise, Apache Superset would not show
CrateDB table metadata in the SQL Lab editor.


2022/06/02 0.27.0
=================
Expand Down
2 changes: 1 addition & 1 deletion src/crate/client/sqlalchemy/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def get_pk_constraint(self, engine, table_name, schema=None, **kw):

def result_fun(result):
rows = result.fetchall()
return set(map(lambda el: el[0], rows))
return list(set(map(lambda el: el[0], rows)))
else:
query = """SELECT constraint_name
FROM information_schema.table_constraints
Expand Down
2 changes: 1 addition & 1 deletion src/crate/client/sqlalchemy/tests/dialect_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_primary_keys(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)

Expand Down

0 comments on commit a1df740

Please sign in to comment.