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 d452e36
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 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
22 changes: 22 additions & 0 deletions tests/orm/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,28 @@ def test_multiple_joins(self):
)


class JoinExecuteTestCase(NativeSessionTestCase):
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 d452e36

Please sign in to comment.