Skip to content

Commit

Permalink
Merge branch 'master' into tom/folder-path-replace
Browse files Browse the repository at this point in the history
  • Loading branch information
Gilbert09 authored Jun 25, 2024
2 parents 5b330c0 + 9b3942a commit cf048b9
Show file tree
Hide file tree
Showing 196 changed files with 5,162 additions and 2,902 deletions.
3 changes: 1 addition & 2 deletions .github/actions/run-backend-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name: Run Django tests
inputs:
python-version:
required: true
description: Python version, e.g. 3.11.9
description: Python version, e.g. 3.10.10
clickhouse-server-image:
required: true
description: ClickHouse server image tag, e.g. clickhouse/clickhouse-server:latest
Expand Down Expand Up @@ -148,7 +148,6 @@ runs:
if: ${{ inputs.segment == 'Core' }}
env:
PERSON_ON_EVENTS_V2_ENABLED: ${{ inputs.person-on-events }}
GROUPS_ON_EVENTS_ENABLED: ${{ inputs.person-on-events }}
shell: bash
run: | # async_migrations covered in ci-async-migrations.yml
pytest ${{
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build-hogql-parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ jobs:
- if: ${{ !endsWith(matrix.os, '-arm') }}
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.10'

- if: ${{ endsWith(matrix.os, '-arm') }}
uses: deadsnakes/[email protected] # Unfortunately actions/setup-python@v4 just doesn't work on ARM! This does
with:
python-version: '3.11'
python-version: '3.10'

# # This is an alternative way to install Python 3.11 on ARM if the above fails
# - if: ${{ endsWith(matrix.os, '-arm') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-backend-update-test-timing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
concurrency: 1
group: 1
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
python-version: '3.11.9'
python-version: '3.10.10'
clickhouse-server-image: 'clickhouse/clickhouse-server:23.12.5.81-alpine'
segment: 'FOSS'
person-on-events: false
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/ci-backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down Expand Up @@ -163,7 +163,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down Expand Up @@ -232,7 +232,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.11.9']
python-version: ['3.10.10']
clickhouse-server-image: ['clickhouse/clickhouse-server:23.12.5.81-alpine']
segment: ['Core']
person-on-events: [false, true]
Expand All @@ -243,7 +243,7 @@ jobs:
- segment: 'Temporal'
person-on-events: false
clickhouse-server-image: 'clickhouse/clickhouse-server:23.12.5.81-alpine'
python-version: '3.11.9'
python-version: '3.10.10'
concurrency: 1
group: 1

Expand Down Expand Up @@ -331,7 +331,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/ci-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ jobs:
OBJECT_STORAGE_SECRET_ACCESS_KEY=object_storage_root_password
GITHUB_ACTION_RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
CELERY_METRICS_PORT=8999
CLOUD_DEPLOYMENT=1
EOT
- name: Start PostHog
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-hog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
if: needs.changes.outputs.hog == 'true'
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-plugin-server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
if: needs.changes.outputs.plugin-server == 'true'
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down Expand Up @@ -207,7 +207,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11.9
python-version: 3.10.10
cache: 'pip'
cache-dependency-path: '**/requirements*.txt'
token: ${{ secrets.POSTHOG_BOT_GITHUB_TOKEN }}
Expand Down
13 changes: 2 additions & 11 deletions bin/build-schema-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ set -e

# Generate schema.py from schema.json
datamodel-codegen \
--class-name='SchemaRoot' --collapse-root-models --target-python-version 3.11 --disable-timestamp \
--class-name='SchemaRoot' --collapse-root-models --target-python-version 3.10 --disable-timestamp \
--use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \
--input frontend/src/queries/schema.json --input-file-type jsonschema \
--output posthog/schema.py --output-model-type pydantic_v2.BaseModel \
--custom-file-header "# mypy: disable-error-code=\"assignment\"" \
--set-default-enum-member --capitalise-enum-members \
--wrap-string-literal

# Format schema.py
ruff format posthog/schema.py

# Check schema.py and autofix
ruff check --fix posthog/schema.py

# HACK: Datamodel-codegen output for enum-type fields with a default is invalid – the default value is a plain string,
# and not the expected enum member. We fix this using sed, which is pretty hacky, but does the job.
# Specifically, we need to replace `Optional[PropertyOperator] = "exact"`
Expand All @@ -28,10 +25,4 @@ if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' -e 's/Optional\[PropertyOperator\] = \("[A-Za-z_]*"\)/Optional[PropertyOperator] = PropertyOperator(\1)/g' posthog/schema.py
else
sed -i -e 's/Optional\[PropertyOperator\] = \("[A-Za-z_]*"\)/Optional[PropertyOperator] = PropertyOperator(\1)/g' posthog/schema.py
fi

# Replace class Foo(str, Enum) with class Foo(StrEnum) for proper handling in format strings in python 3.11
# Remove this when https://github.com/koxudaxi/datamodel-code-generator/issues/1313 is resolved

sed -i -e 's/str, Enum/StrEnum/g' posthog/schema.py
sed -i 's/from enum import Enum/from enum import Enum, StrEnum/g' posthog/schema.py
fi
1 change: 1 addition & 0 deletions bin/e2e-test-runner
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export PGUSER="${PGUSER:=posthog}"
export PGPASSWORD="${PGPASSWORD:=posthog}"
export PGPORT="${PGPORT:=5432}"
export DATABASE_URL="postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${DATABASE}"
export CLOUD_DEPLOYMENT=1

trap "trap - SIGTERM && kill -- -$$" SIGINT SIGTERM EXIT

Expand Down
27 changes: 19 additions & 8 deletions cypress/e2e/insights.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,24 @@ describe('Insights', () => {
cy.get('[data-attr=insight-tags]').should('not.exist')
})

describe('view source', () => {
it('can open the query editor', () => {
insight.newInsight('TRENDS')
insight.save()
cy.get('[data-attr="more-button"]').click()
cy.get('[data-attr="show-insight-source"]').click()
cy.get('[data-attr="query-editor"]').should('exist')
})
it('can edit via the query editor', () => {
insight.newInsight('TRENDS')
insight.save()
cy.get('[data-attr="more-button"]').click()
cy.get('[data-attr="show-insight-source"]').click()
// Find "day"
cy.get('.monaco-editor')
.click()
// change subject to currently focused element
.focused()
.type('{ctrl}f')
.focused()
.type('day')

// Remove day and add hour
cy.get('.monaco-editor').click().focused().type('{leftArrow}{leftArrow}{backspace}{backspace}{backspace}hour')
cy.get('[data-attr=query-editor-save]').click()

cy.get('[data-attr="interval-filter').contains('hour').should('exist')
})
})
32 changes: 32 additions & 0 deletions cypress/e2e/organizationSettings.cy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
import { urls } from 'scenes/urls'

// For tests related to team members administration please see `inviteMembers.js`
describe('Organization settings', () => {
beforeEach(() => {
cy.intercept('/api/billing/', { fixture: 'api/billing/billing.json' })
cy.useSubscriptionStatus('subscribed')
})
it('can navigate to organization settings', () => {
cy.get('[data-attr=menu-item-me]').click()
cy.get('[data-attr=top-menu-item-org-settings]').click()
cy.location('pathname').should('include', '/settings/organization')
})
it('can create a new organization', () => {
cy.visit(urls.settings('organization'), {
onLoad(win: Cypress.AUTWindow) {
;(win as any).POSTHOG_APP_CONTEXT.preflight.cloud = true
},
})
cy.get('[data-attr=breadcrumb-organization]').click()
cy.get('[data-attr=new-organization-button]').click()
cy.get('[data-attr=organization-name-input]').type('New Organization')
cy.get('[data-attr=create-organization-ok]').click()
cy.get('[data-attr=organization-name-input-settings]').should('have.value', 'New Organization')
})
it('can delete an organization', () => {
cy.visit(urls.settings('organization'), {
onLoad(win: Cypress.AUTWindow) {
;(win as any).POSTHOG_APP_CONTEXT.preflight.cloud = true
},
})
cy.get('[data-attr=organization-name-input-settings]').should('have.value', 'New Organization')
cy.get('[data-attr=delete-organization-button]').click()
cy.get('[data-attr=delete-organization-confirmation-input]').type('New Organization')
cy.get('[data-attr=delete-organization-ok]').click()
// it redirects to the homepage after deleting the organization
cy.get('[data-attr=organization-name-input-settings]').should('not.exist')
cy.get('[data-attr=top-bar-name]').should('contain.text', 'Homepage')
})
})
3 changes: 3 additions & 0 deletions cypress/support/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'givens/setup'
import './commands'
import 'cypress-axe'
import { decideResponse } from '../fixtures/api/decide'
import { urls } from 'scenes/urls'

try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand Down Expand Up @@ -50,6 +51,8 @@ beforeEach(() => {

if (Cypress.spec.name.includes('before-onboarding')) {
cy.visit('/?no-preloaded-app-context=true')
} else if (Cypress.spec.name.includes('organizationSettings')) {
cy.visit(urls.settings('organization'))
} else {
cy.visit('/insights')
cy.wait('@getInsights').then(() => {
Expand Down
2 changes: 1 addition & 1 deletion ee/api/test/__snapshots__/test_time_to_see_data.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"first_name": "",
"last_name": "",
"email": "",
"is_email_verified": null
"is_email_verified": false
}
},
"children": [
Expand Down
93 changes: 22 additions & 71 deletions ee/clickhouse/models/test/test_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from posthog.models.filters import Filter
from posthog.models.instance_setting import (
get_instance_setting,
override_instance_config,
)
from posthog.models.organization import Organization
from posthog.models.property import Property, TableWithProperties
Expand Down Expand Up @@ -1037,38 +1036,6 @@ def test_get_property_string_expr(self):
)
self.assertEqual(string_expr, ('"mat_pp_some_mat_prop2"', True))

def test_get_property_string_expr_groups(self):
if not get_instance_setting("GROUPS_ON_EVENTS_ENABLED"):
return

materialize("events", "some_mat_prop3", table_column="group2_properties")

string_expr = get_property_string_expr(
"events",
"some_mat_prop3",
"x",
"properties",
table_alias="e",
materialised_table_column="group2_properties",
)
self.assertEqual(string_expr, ('e."mat_gp2_some_mat_prop3"', True))

string_expr = get_property_string_expr(
"events",
"some_mat_prop3",
"'x'",
"gp_props_alias",
table_alias="e",
materialised_table_column="group1_properties",
)
self.assertEqual(
string_expr,
(
"replaceRegexpAll(JSONExtractRaw(e.gp_props_alias, 'x'), '^\"|\"$', '')",
False,
),
)


@pytest.mark.django_db
def test_parse_prop_clauses_defaults(snapshot):
Expand Down Expand Up @@ -1255,22 +1222,7 @@ def test_breakdown_query_expression(
{"breakdown_param_1": "$browser"},
),
('array("mat_pp_$browser") AS value', {"breakdown_param_1": "$browser"}),
),
(
["$browser", "$browser_version"],
"events",
"prop",
"properties",
"group2_properties",
(
"array(replaceRegexpAll(JSONExtractRaw(properties, %(breakdown_param_1)s), '^\"|\"$', ''),replaceRegexpAll(JSONExtractRaw(properties, %(breakdown_param_2)s), '^\"|\"$', '')) AS prop",
{"breakdown_param_1": "$browser", "breakdown_param_2": "$browser_version"},
),
(
"""array("mat_gp2_$browser",replaceRegexpAll(JSONExtractRaw(properties, %(breakdown_param_2)s), '^\"|\"$', '')) AS prop""",
{"breakdown_param_1": "$browser", "breakdown_param_2": "$browser_version"},
),
),
)
]


Expand All @@ -1289,31 +1241,30 @@ def test_breakdown_query_expression_materialised(
expected_with: str,
expected_without: str,
):
with override_instance_config("GROUPS_ON_EVENTS_ENABLED", True):
from posthog.models.team import util
from posthog.models.team import util

util.can_enable_actor_on_events = True
util.can_enable_actor_on_events = True

materialize(table, breakdown[0], table_column="properties")
actual = get_single_or_multi_property_string_expr(
breakdown,
table,
query_alias,
column,
materialised_table_column=materialise_column,
)
assert actual == expected_with

materialize(table, breakdown[0], table_column=materialise_column) # type: ignore
actual = get_single_or_multi_property_string_expr(
breakdown,
table,
query_alias,
column,
materialised_table_column=materialise_column,
)
materialize(table, breakdown[0], table_column="properties")
actual = get_single_or_multi_property_string_expr(
breakdown,
table,
query_alias,
column,
materialised_table_column=materialise_column,
)
assert actual == expected_with

materialize(table, breakdown[0], table_column=materialise_column) # type: ignore
actual = get_single_or_multi_property_string_expr(
breakdown,
table,
query_alias,
column,
materialised_table_column=materialise_column,
)

assert actual == expected_without
assert actual == expected_without


@pytest.fixture
Expand Down
Loading

0 comments on commit cf048b9

Please sign in to comment.