Skip to content

Commit

Permalink
Fix types, fix tag_queries
Browse files Browse the repository at this point in the history
  • Loading branch information
webjunkie committed Jan 12, 2024
1 parent 0a185f2 commit db88128
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions posthog/api/mixins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TypeVar, Type, Generic
from typing import TypeVar, Type

from pydantic import BaseModel, ValidationError

Expand All @@ -7,7 +7,7 @@
T = TypeVar("T", bound=BaseModel)


class PydanticModelMixin(Generic[T]):
class PydanticModelMixin:
def get_model(self, data: dict, model: Type[T]) -> T:
try:
return model.model_validate(data)
Expand Down
10 changes: 4 additions & 6 deletions posthog/api/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def create(self, request, *args, **kwargs) -> Response:
)
return Response(query_status.model_dump())

tag_queries(query=request.data["query"])
try:
result = process_query_model(self.team, data.query, refresh_requested=data.refresh)
return Response(result)
Expand All @@ -87,12 +88,6 @@ def create(self, request, *args, **kwargs) -> Response:
capture_exception(e)
raise e

@extend_schema(
description="(Experimental)",
responses={
200: OpenApiResponse(description="Query status"),
},
)
@extend_schema(
description="(Experimental)",
responses={
Expand All @@ -105,6 +100,9 @@ def retrieve(self, request: Request, pk=None, *args, **kwargs) -> JsonResponse:

@extend_schema(
description="(Experimental)",
responses={
204: OpenApiResponse(description="Query cancelled"),
},
)
def destroy(self, request, pk=None, *args, **kwargs):
cancel_query(self.team.pk, pk)
Expand Down
2 changes: 1 addition & 1 deletion posthog/api/services/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def process_query(
refresh_requested: Optional[bool] = False,
) -> dict:
model = QuerySchemaRoot.model_validate(query_json)
tag_queries(query=query_json)
return process_query_model(
team,
model.root,
Expand All @@ -67,7 +68,6 @@ def process_query_model(
limit_context: Optional[LimitContext] = None,
refresh_requested: Optional[bool] = False,
) -> dict:
tag_queries(query=query.kind) # TODO: ?
result: dict | BaseModel

if isinstance(query, QUERY_WITH_RUNNER): # type: ignore
Expand Down

0 comments on commit db88128

Please sign in to comment.