:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(ci): stop the uuidt model check from blocking master (#108489)
Raúl Negrón-Oterob558f01f31d4
diff --git a/.github/actions/semgrep-ci/action.yml b/.github/actions/semgrep-ci/action.ymlindex ae2a7dba9b69..a1620777d461 100644--- a/.github/actions/semgrep-ci/action.yml+++ b/.github/actions/semgrep-ci/action.yml@@ -20,6 +20,14 @@ inputs:patterns with a leading slash (--include /bin); unanchored patterns alsomatch same-named nested directories anywhere in the tree.required: true+ full-scan:+ description: >+ 'true' runs `semgrep scan --error` over the whole tree instead of the+ diff-aware `semgrep ci`, so a pull request reports every finding, the way a+ push does. Set it when the pull request changes a rule or the scan setup:+ the diff-aware scan cannot see what an edited rule matches in unchanged code.+ required: false+ default: 'false'runs:using: composite@@ -29,6 +37,7 @@ runs:env:SEMGREP_ARGS: ${{ inputs.args }}SEMGREP_IMAGE: ${{ inputs.image }}+ FULL_SCAN: ${{ inputs.full-scan }}# Lets semgrep resolve the PR merge-base with one API call instead of# deepening fetches (cli/src/semgrep/meta.py GithubMeta._find_branchoff_point)GH_TOKEN: ${{ github.token }}@@ -55,6 +64,12 @@ runs:semgrep_args=($SEMGREP_ARGS)set +f+ if [[ "$FULL_SCAN" == 'true' ]]; then+ semgrep_command=(scan --error)+ else+ semgrep_command=(ci)+ fi+docker run --rm \-v "$GITHUB_WORKSPACE:/src" -w /src \-v "$GITHUB_EVENT_PATH:/github-event.json:ro" \@@ -65,4 +80,5 @@ runs:-e GITHUB_REPOSITORY_ID -e GITHUB_REPOSITORY_OWNER_ID \-e GH_TOKEN \"$SEMGREP_IMAGE" \- sh -c 'git config --global --add safe.directory /src && exec semgrep ci --metrics=off --verbose --timeout 300 "$@"' sh "${semgrep_args[@]}"+ sh -c 'git config --global --add safe.directory /src && exec semgrep "$@"' sh \+ "${semgrep_command[@]}" --metrics=off --verbose --timeout 300 "${semgrep_args[@]}"diff --git a/.github/workflows/ci-security.yaml b/.github/workflows/ci-security.yamlindex d4acf337d8c1..e4161b433aac 100644--- a/.github/workflows/ci-security.yaml+++ b/.github/workflows/ci-security.yaml@@ -35,6 +35,8 @@ jobs:devex: ${{ steps.oversized.outputs.force_all || steps.filter.outputs.devex || 'true' }}test-rules: ${{ steps.oversized.outputs.force_all || steps.filter.outputs.test-rules || 'true' }}desktop: ${{ steps.oversized.outputs.force_all || steps.filter.outputs.desktop || 'true' }}+ # Pushes default to 'false' because `semgrep ci` already scans the whole tree on a push.+ scan-setup: ${{ steps.oversized.outputs.force_all || steps.filter.outputs.scan-setup || 'false' }}steps:- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2with:@@ -138,6 +140,11 @@ jobs:desktop:- 'products/desktop/**'- '.github/workflows/ci-security.yaml'+ # A change to the rules or the scan setup can change findings in+ # unchanged code, so the jobs that pass local rules scan the whole tree.+ scan-setup:+ - '.semgrep/rules/security/**'+ - '.github/workflows/ci-security.yaml'semgrep-python:needs: changes@@ -167,6 +174,7 @@ jobs:uses: ./.github/actions/semgrep-ciwith:image: ${{ env.SEMGREP_IMAGE }}+ full-scan: ${{ needs.changes.outputs.scan-setup }}args: >---config p/python--config p/owasp-top-ten@@ -287,6 +295,7 @@ jobs:uses: ./.github/actions/semgrep-ciwith:image: ${{ env.SEMGREP_IMAGE }}+ full-scan: ${{ needs.changes.outputs.scan-setup }}args: >---config .semgrep/rules/security--config p/javascript@@ -332,6 +341,7 @@ jobs:uses: ./.github/actions/semgrep-ciwith:image: ${{ env.SEMGREP_IMAGE }}+ full-scan: ${{ needs.changes.outputs.scan-setup }}args: >---config .semgrep/rules/security/prefer-codegen-api.yaml--include /productsdiff --git a/.semgrep/rules/devex/no-new-uuidt-models.py b/.semgrep/rules/devex/no-new-uuidt-models.pynew file mode 100644index 000000000000..a75057c940c8--- /dev/null+++ b/.semgrep/rules/devex/no-new-uuidt-models.py@@ -0,0 +1,18 @@+# Test cases for no-new-uuidt-models.+# ruff: noqa+from posthog.models.utils import UUIDModel, UUIDTModel+++# ruleid: no-new-uuidt-models+class LegacyKey(UUIDTModel):+ pass+++# ruleid: no-new-uuidt-models+class LegacyKeyWithMixin(TeamScopedRootMixin, UUIDTModel):+ pass+++# ok: no-new-uuidt-models+class CurrentKey(UUIDModel):+ passdiff --git a/.semgrep/rules/devex/no-new-uuidt-models.yaml b/.semgrep/rules/devex/no-new-uuidt-models.yamlnew file mode 100644index 000000000000..b0cb4850ba60--- /dev/null+++ b/.semgrep/rules/devex/no-new-uuidt-models.yaml@@ -0,0 +1,31 @@+rules:+ - id: no-new-uuidt-models+ message: >-+ `UUIDTModel` predates the UUIDv7 spec and is not for new models. Its+ ids do not sort or compare as uuid7 ids do, so a value that travels+ between systems stops matching one written by anything newer. Inherit+ from `UUIDModel` instead, which sets a `uuid7` primary key. See+ `posthog/models/utils.py`.+ severity: WARNING+ languages: [python]+ paths:+ include:+ - '**/models.py'+ - '**/models/**'+ exclude:+ - '**/migrations/**'+ - '**/test/**'+ - '**/tests/**'+ - '**/*_test.py'+ - '**/test_*.py'+ - '**/conftest*.py'+ # The match covers only the base class name, so an edit inside an existing+ # model's body keeps its finding grandfathered in the PR baseline diff.+ patterns:+ - pattern: |+ class $NAME(..., $BASE, ...):+ ...+ - metavariable-regex:+ metavariable: $BASE+ regex: ^UUIDTModel$+ - focus-metavariable: $BASEdiff --git a/.semgrep/rules/security/prefer-uuid7-django-pk.yaml b/.semgrep/rules/security/prefer-uuid7-django-pk.yamlindex fb21cd8452f6..da40a6221984 100644--- a/.semgrep/rules/security/prefer-uuid7-django-pk.yaml+++ b/.semgrep/rules/security/prefer-uuid7-django-pk.yaml@@ -14,18 +14,11 @@ rules:for `UUIDModel` and `uuid7`.severity: WARNINGlanguages: [python]- pattern-either:- - patterns:- - pattern-either:- - pattern: models.UUIDField(..., default=uuid.uuid4, ...)- - pattern: models.UUIDField(..., default=uuid4, ...)- - pattern: models.UUIDField(..., primary_key=True, ...)- # `UUIDTModel` predates the UUIDv7 spec and its own docstring says it is not for new- # models. Its ids do not sort or compare as uuid7 ids do, so a value that travels between- # systems stops matching one written by anything newer.- - pattern: |- class $NAME(..., UUIDTModel, ...):- ...+ patterns:+ - pattern-either:+ - pattern: models.UUIDField(..., default=uuid.uuid4, ...)+ - pattern: models.UUIDField(..., default=uuid4, ...)+ - pattern: models.UUIDField(..., primary_key=True, ...)paths:include:- '**/models.py'