Skip to content

Commit

Permalink
Fix unhashable type dict
Browse files Browse the repository at this point in the history
  • Loading branch information
xzkostyan committed Oct 17, 2024
1 parent 099883a commit 1ad3bb3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
5 changes: 4 additions & 1 deletion clickhouse_sqlalchemy/drivers/compilers/sqlcompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def visit_join(self, join, asfrom=False, **kwargs):

flags = join.full
if not isinstance(flags, dict):
flags = {'full': flags}
if isinstance(flags, tuple):
flags = dict(flags)
else:
flags = {'full': flags}
# need to make a variable to prevent leaks in some debuggers
join_type = flags.get('type')
if join_type is None:
Expand Down
2 changes: 1 addition & 1 deletion clickhouse_sqlalchemy/orm/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def join(self, *props, **kwargs):
x_spec = dict(spec)
# use 'full' key to pass extra flags
x_spec['full'] = x[-1]['full']
x[-1]['full'] = x_spec
x[-1]['full'] = tuple(x_spec.items())

return rv

Expand Down
4 changes: 2 additions & 2 deletions clickhouse_sqlalchemy/sql/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def drop(self, bind=None, checkfirst=False, if_exists=False):

def join(self, right, onclause=None, isouter=False, full=False,
type=None, strictness=None, distribution=None):
flags = {
flags = tuple({
'full': full,
'type': type,
'strictness': strictness,
'distribution': distribution
}
}.items())
return Join(self, right, onclause=onclause, isouter=isouter,
full=flags)

Expand Down
4 changes: 2 additions & 2 deletions clickhouse_sqlalchemy/sql/selectable.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def left_array_join(self, *columns):

def join(self, right, onclause=None, isouter=False, full=False, type=None,
strictness=None, distribution=None):
flags = {
flags = tuple({
'full': full,
'type': type,
'strictness': strictness,
'distribution': distribution
}
}.items())
return Join(self, right, onclause=onclause, isouter=isouter,
full=flags)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def read_version():
'sqlalchemy>=1.4.24,<1.5',
'requests',
'clickhouse-driver>=0.1.2',
'asynch>=0.2.2',
'asynch>=0.2.2,<=0.2.4',
],
# Registering `clickhouse` as dialect.
entry_points={
Expand Down
25 changes: 25 additions & 0 deletions tests/orm/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from clickhouse_sqlalchemy import types, Table, engines
from clickhouse_sqlalchemy.ext.clauses import Lambda
from tests.testcase import NativeSessionTestCase, CompilationTestCase
from tests.util import require_server_version


class SelectTestCase(CompilationTestCase):
Expand Down Expand Up @@ -394,6 +395,30 @@ def test_multiple_joins(self):
)


class JoinExecuteTestCase(NativeSessionTestCase):
@require_server_version(19, 3, 3)
# this not works in 18.x
def test_execute_full_join(self):
numbers = Table(
'numbers', self.metadata(),
Column('number', types.UInt64, primary_key=True),
schema='system'
)

sub_query1 = self.session.query(numbers.c.number.label('x')) \
.limit(1) \
.subquery()

sub_query2 = self.session.query(numbers.c.number.label('x')) \
.limit(1) \
.subquery()

query = self.session.query(sub_query1.c.x, sub_query2.c.x) \
.outerjoin(sub_query2, sub_query1.c.x == sub_query2.c.x)

self.assertEqual(query.all(), [(0, 0)])


class YieldTest(NativeSessionTestCase):
def test_yield_per_and_execution_options(self):
numbers = Table(
Expand Down

0 comments on commit 1ad3bb3

Please sign in to comment.