engine: fix filtering of members of unjoined dimensions (#44289)

This commit is contained in:
Benjamin Dauvergne 2020-06-19 16:27:33 +02:00
parent 203605dec3
commit be85302f2d
2 changed files with 8 additions and 6 deletions

View File

@ -163,18 +163,20 @@ class EngineDimension(object):
conditions = []
for dimension_name, values in filters:
dimension = self.engine_cube.dimensions[dimension_name]
if not (set(dimension.join or []) & set(self.join or [])):
# we build a filter on two sufficient conditions :
# * the filter is on the same dimension as the one we currently query for members,
# * or, the dimension of the filter has impact on a join shared with the current dimension.
if dimension_name != self.name and not (set(dimension.join or []) & set(self.join or [])):
continue
# assert dimension.filter
condition, values = dimension.build_filter(values)
if not condition:
continue
with self.engine.get_cursor() as cursor: # Ugly...
condition = force_text(cursor.mogrify(condition, values))
if dimension.filter_needs_join and dimension.join:
joins.update(dimension.join)
conditions.append(condition)
joins.update(dimension.join)
# add all joins needed by the filter's dimension
if dimension.join:
joins.update(dimension.join)
with self.engine.get_cursor() as cursor:
sql = self.members_query

View File

@ -95,7 +95,7 @@ def test_string_dimension(schema1, app, admin):
assert get_table(response) == [['String', 'a', 'b', 'c', 'Aucun(e)'], ['number of rows', '11', '2', '3', '1']]
form.set('filter__string', ['a', 'b', '__none__'])
response = form.submit('visualize')
assert get_table(response) == [['String', 'a', 'b', 'c', 'Aucun(e)'], ['number of rows', '11', '2', '0', '1']]
assert get_table(response) == [['String', 'a', 'b', 'Aucun(e)'], ['number of rows', '11', '2', '1']]
def test_string_dimension_json_data(schema1, app, admin):