Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Mar 27, 2024
1 parent fac8008 commit a205c68
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 50 deletions.
11 changes: 4 additions & 7 deletions posthog/hogql_queries/legacy_compatibility/clean_properties.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from posthog.schema import PropertyGroupFilter


def clean_global_properties(properties: dict | list[dict] | None):
if properties is None or len(properties) == 0:
# empty properties
Expand All @@ -12,14 +9,14 @@ def clean_global_properties(properties: dict | list[dict] | None):
"type": "AND",
"values": [{"type": "AND", "values": properties}],
}
return PropertyGroupFilter(**clean_property_group_filter(properties))
return clean_property_group_filter(properties)
elif isinstance(properties, list):
# list of property filters
properties = {
"type": "AND",
"values": [{"type": "AND", "values": properties}],
}
return PropertyGroupFilter(**clean_property_group_filter(properties))
return clean_property_group_filter(properties)
elif (
isinstance(properties, dict)
and properties.get("type") in ["AND", "OR"]
Expand All @@ -30,10 +27,10 @@ def clean_global_properties(properties: dict | list[dict] | None):
"type": "AND",
"values": [properties],
}
return PropertyGroupFilter(**clean_property_group_filter(properties))
return clean_property_group_filter(properties)
else:
# property group filter
return PropertyGroupFilter(**clean_property_group_filter(properties))
return clean_property_group_filter(properties)


def clean_entity_properties(properties: list[dict] | dict | None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
from posthog.hogql_queries.legacy_compatibility.clean_properties import clean_entity_properties, clean_global_properties
from posthog.schema import (
CohortPropertyFilter,
EventPropertyFilter,
FilterLogicalOperator,
PropertyGroupFilter,
PropertyGroupFilterValue,
PropertyOperator,
)
from posthog.test.base import BaseTest


Expand All @@ -25,17 +17,15 @@ def test_handles_old_style_properties(self):

self.assertEqual(
result,
PropertyGroupFilter(
type=FilterLogicalOperator.AND,
values=[
PropertyGroupFilterValue(
type=FilterLogicalOperator.AND,
values=[
EventPropertyFilter(key="utm_medium", value="email", operator=PropertyOperator.icontains)
],
)
{
"type": "AND",
"values": [
{
"type": "AND",
"values": [{"key": "utm_medium", "operator": "icontains", "type": "event", "value": "email"}],
}
],
),
},
)

def test_handles_property_filter_lists(self):
Expand All @@ -45,15 +35,15 @@ def test_handles_property_filter_lists(self):

self.assertEqual(
result,
PropertyGroupFilter(
type=FilterLogicalOperator.AND,
values=[
PropertyGroupFilterValue(
type=FilterLogicalOperator.AND,
values=[CohortPropertyFilter(key="id", value=636)],
)
{
"type": "AND",
"values": [
{
"type": "AND",
"values": [{"key": "id", "type": "cohort", "value": 636}],
}
],
),
},
)

def test_handles_property_group_filters(self):
Expand All @@ -66,15 +56,15 @@ def test_handles_property_group_filters(self):

self.assertEqual(
result,
PropertyGroupFilter(
type=FilterLogicalOperator.AND,
values=[
PropertyGroupFilterValue(
type=FilterLogicalOperator.AND,
values=[CohortPropertyFilter(key="id", value=850)],
)
{
"type": "AND",
"values": [
{
"type": "AND",
"values": [{"key": "id", "type": "cohort", "value": 850}],
}
],
),
},
)

def test_handles_property_group_filters_values(self):
Expand All @@ -87,15 +77,15 @@ def test_handles_property_group_filters_values(self):

self.assertEqual(
result,
PropertyGroupFilter(
type=FilterLogicalOperator.AND,
values=[
PropertyGroupFilterValue(
type=FilterLogicalOperator.AND,
values=[CohortPropertyFilter(key="id", value=850)],
)
{
"type": "AND",
"values": [
{
"type": "AND",
"values": [{"key": "id", "type": "cohort", "value": 850}],
}
],
),
},
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,7 @@ def test_series_properties(self):
self.assertEqual(
query.series,
[
EventsNode(event="$pageview", name="$pageview", properties=[]),
EventsNode(event="$pageview", name="$pageview", properties=None),
EventsNode(
event="$pageview",
name="$pageview",
Expand Down

0 comments on commit a205c68

Please sign in to comment.