Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with Apache Superset by showing CrateDB table metadata in the SQL Lab editor #426

Closed
wants to merge 1 commit into from
Closed
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
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"])
Copy link
Member Author

@amotl amotl Jun 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That test will now become flaky. The sample where it happened was on Python 3.10 with SQLAlchemy 1.3.24.

 Failure in test test_primary_keys (crate.client.sqlalchemy.tests.dialect_test.DialectTest)
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/unittest/case.py", line 591, in run
    self._callTestMethod(testMethod)
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/unittest/case.py", line 549, in _callTestMethod
    method()
  File "/opt/hostedtoolcache/Python/3.10.5/x64/lib/python3.10/unittest/mock.py", line 1369, in patched
    return func(*newargs, **newkeywargs)
  File "/home/runner/work/crate-python/crate-python/src/crate/client/sqlalchemy/tests/dialect_test.py", line 81, in test_primary_keys
    eq_(insp.get_pk_constraint("characters")['constrained_columns'], ["id", "id2", "id3"])
  File "/home/runner/work/crate-python/crate-python/.venv/lib/python3.10/site-packages/sqlalchemy/testing/assertions.py", line 238, in eq_
    assert a == b, msg or "%r != %r" % (a, b)
AssertionError: ['id2', 'id', 'id3'] != ['id', 'id2', 'id3']

-- https://github.com/crate/crate-python/runs/6969929509#step:4:392

self.fake_cursor.fetchall.assert_called_once_with()
in_("information_schema.key_column_usage", self.executed_statement)

Expand Down