Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't use DB choice for hog functions #27069

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions posthog/api/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
TYPES_WITH_COMPILED_FILTERS,
TYPES_WITH_TRANSPILED_FILTERS,
TYPES_WITH_JAVASCRIPT_SOURCE,
HogFunctionType,
)
from posthog.models.plugin import TranspilerError
from posthog.plugins.plugin_server_api import create_hog_invocation_test
Expand Down Expand Up @@ -88,6 +89,8 @@ class HogFunctionSerializer(HogFunctionMinimalSerializer):
template = HogFunctionTemplateSerializer(read_only=True)
masking = HogFunctionMaskingSerializer(required=False, allow_null=True)

type = serializers.ChoiceField(choices=HogFunctionType.choices, required=False, allow_null=True)

class Meta:
model = HogFunction
fields = [
Expand Down
19 changes: 19 additions & 0 deletions posthog/api/test/test_hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,25 @@ def test_inputs_required(self, *args):
"attr": "inputs__url",
}

def test_validation_error_on_invalid_type(self, *args):
payload = {
"name": "Fetch URL",
"hog": "fetch(inputs.url);",
"inputs_schema": [
{"key": "url", "type": "string", "label": "Webhook URL", "required": True},
],
"type": "invalid_type",
}
# Check required
res = self.client.post(f"/api/projects/{self.team.id}/hog_functions/", data={**payload})
assert res.status_code == status.HTTP_400_BAD_REQUEST, res.json()
assert res.json() == {
"type": "validation_error",
"code": "invalid_choice",
"detail": '"invalid_type" is not a valid choice.',
"attr": "type",
}

def test_inputs_mismatch_type(self, *args):
payload = {
"name": "Fetch URL",
Expand Down
17 changes: 17 additions & 0 deletions posthog/migrations/0535_alter_hogfunction_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.15 on 2024-12-19 14:58

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("posthog", "0534_team_cookieless_server_hash_mode"),
]

operations = [
migrations.AlterField(
model_name="hogfunction",
name="type",
field=models.CharField(blank=True, max_length=24, null=True),
),
]
2 changes: 1 addition & 1 deletion posthog/migrations/max_migration.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0534_team_cookieless_server_hash_mode
0535_alter_hogfunction_type
2 changes: 1 addition & 1 deletion posthog/models/hog_functions/hog_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Meta:
deleted = models.BooleanField(default=False)
updated_at = models.DateTimeField(auto_now=True)
enabled = models.BooleanField(default=False)
type = models.CharField(max_length=24, choices=HogFunctionType.choices, null=True, blank=True)
type = models.CharField(max_length=24, null=True, blank=True)

icon_url = models.TextField(null=True, blank=True)

Expand Down
Loading