Skip to content

Commit

Permalink
failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pauldambra committed Dec 21, 2023
1 parent fdae0df commit 3a512ab
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 45 deletions.
11 changes: 0 additions & 11 deletions ee/clickhouse/models/test/__snapshots__/test_property.ambr

This file was deleted.

11 changes: 10 additions & 1 deletion ee/clickhouse/models/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,16 @@ def test_events(db, team) -> List[UUID]:
event="$pageview",
team=team,
distinct_id="whatever",
# new line character shouldn't be matched by a single regex dot
properties={"email": "test@post\nhog.com"},
),
_create_event(
event="$pageview",
team=team,
distinct_id="whatever",
# not a new line character - instead a single character - should match
properties={"email": "[email protected]"},
),
]


Expand Down Expand Up @@ -1756,7 +1764,8 @@ def clean_up_materialised_columns():
id="can match before date only values",
),
# Regression test, we were previously matching on newline characters
pytest.param(Property(key="email", value=r"[email protected]", operator="regex"), []),
# this should match one of two possibles (how are you supposed to figure out the expected index 🙈)
pytest.param(Property(key="email", value=r"[email protected]", operator="regex"), [28]),
]


Expand Down
26 changes: 0 additions & 26 deletions posthog/api/test/__snapshots__/test_query.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,6 @@
allow_experimental_object_type=1
'
---
# name: TestQuery.test_event_property_regex_is_patched_for_dotall_setting
'
/* user_id:0 request:_snapshot_ */
SELECT replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'example_value'), ''), 'null'), '^"|"$', '') AS example_value
FROM events
WHERE and(equals(events.team_id, 2), match(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'example_value'), ''), 'null'), '^"|"$', ''), '(?-s)a.b'), equals(events.event, 'demonstrate dot all'), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
ORDER BY replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, 'example_value'), ''), 'null'), '^"|"$', '') ASC
LIMIT 101
OFFSET 0 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
'
---
# name: TestQuery.test_event_property_regex_is_patched_for_dotall_setting_materialized
'
/* user_id:0 request:_snapshot_ */
SELECT nullIf(nullIf(events.mat_example_value, ''), 'null') AS example_value
FROM events
WHERE and(equals(events.team_id, 2), match(nullIf(nullIf(events.mat_example_value, ''), 'null'), '(?-s)a.b'), equals(events.event, 'demonstrate dot all'), less(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-10 12:14:05.000000', 6, 'UTC')), greater(toTimeZone(events.timestamp, 'UTC'), toDateTime64('2020-01-09 12:14:00.000000', 6, 'UTC')))
ORDER BY nullIf(nullIf(events.mat_example_value, ''), 'null') ASC
LIMIT 101
OFFSET 0 SETTINGS readonly=2,
max_execution_time=60,
allow_experimental_object_type=1
'
---
# name: TestQuery.test_events_query_all_time_date
'
/* user_id:0 request:_snapshot_ */
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/test/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,8 @@ def test_event_property_regex_is_patched_for_dotall_setting(self):
properties=[{"key": "example_value", "value": "a.b", "operator": "regex", "type": "event"}],
)
response = self.client.post(f"/api/projects/{self.team.id}/query/", {"query": query.dict()}).json()
# assert [x[0] for x in response["results"]] == ['aab', 'abb']
assert [x[0] for x in response["results"]] == []
assert "(?-s)" in response["hogql"]
assert [x[0] for x in response["results"]] == ["aab", "abb"]

@also_test_with_materialized_columns(event_properties=["key"], person_properties=["email"])
@snapshot_clickhouse_queries
Expand Down
8 changes: 4 additions & 4 deletions posthog/hogql/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,16 @@ def visit_compare_operation(self, node: ast.CompareOperation):
elif node.op == ast.CompareOperationOp.GlobalNotIn:
op = f"globalNotIn({left}, {right})"
elif node.op == ast.CompareOperationOp.Regex:
op = f"match({left}, {right})"
op = f"match({left}, concat('(?-s)', {right}))"
value_if_both_sides_are_null = True
elif node.op == ast.CompareOperationOp.NotRegex:
op = f"not(match({left}, {right}))"
op = f"not(match({left}, concat('(?-s)', {right})))"
value_if_one_side_is_null = True
elif node.op == ast.CompareOperationOp.IRegex:
op = f"match({left}, concat('(?i)', {right}))"
op = f"match({left}, concat('(?i-s)', {right}))"
value_if_both_sides_are_null = True
elif node.op == ast.CompareOperationOp.NotIRegex:
op = f"not(match({left}, concat('(?i)', {right})))"
op = f"not(match({left}, concat('(?i-s)', {right})))"
value_if_one_side_is_null = True
elif node.op == ast.CompareOperationOp.Gt:
op = f"greater({left}, {right})"
Expand Down
2 changes: 1 addition & 1 deletion posthog/hogql/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_property_to_expr_event(self):
)
self.assertEqual(
self._property_to_expr({"type": "event", "key": "a", "value": ".*", "operator": "not_regex"}),
self._parse_expr("not(match(properties.a, '.*'))"),
self._parse_expr("not(match(properties.a, '(?-s).*'))"),
)
self.assertEqual(
self._property_to_expr({"type": "event", "key": "a", "value": [], "operator": "exact"}),
Expand Down

0 comments on commit 3a512ab

Please sign in to comment.