Skip to content

Commit

Permalink
fix(insights): convert floats to integers (#19834)
Browse files Browse the repository at this point in the history
* fix(insights): breakdown numbers are integers

* few more integers

* fix 2 mypy errors
  • Loading branch information
mariusandra authored Jan 18, 2024
1 parent f92330c commit 4c9977b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
20 changes: 10 additions & 10 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "array"
},
"id": {
"type": "number"
"type": "integer"
},
"kind": {
"const": "ActionsNode",
Expand Down Expand Up @@ -334,16 +334,16 @@
"$ref": "#/definitions/BreakdownKeyType"
},
"breakdown_group_type_index": {
"type": ["number", "null"]
"type": "integer"
},
"breakdown_hide_other_aggregation": {
"type": ["boolean", "null"]
},
"breakdown_histogram_bin_count": {
"type": "number"
"type": "integer"
},
"breakdown_limit": {
"type": "number"
"type": "integer"
},
"breakdown_normalize_url": {
"type": "boolean"
Expand Down Expand Up @@ -965,7 +965,7 @@
"type": "string"
},
"limit": {
"type": "number"
"type": "integer"
},
"math": {
"anyOf": [
Expand Down Expand Up @@ -2314,7 +2314,7 @@
"additionalProperties": false,
"properties": {
"cohort": {
"type": "number"
"type": "integer"
},
"distinctId": {
"type": "string"
Expand All @@ -2331,10 +2331,10 @@
"type": "string"
},
"limit": {
"type": "number"
"type": "integer"
},
"offset": {
"type": "number"
"type": "integer"
},
"properties": {
"description": "Properties configurable in the interface",
Expand Down Expand Up @@ -3661,7 +3661,7 @@
},
"teamId": {
"description": "Project to filter on. Defaults to current project",
"type": "number"
"type": "integer"
}
},
"required": ["kind"],
Expand All @@ -3684,7 +3684,7 @@
},
"teamId": {
"description": "Project to filter on. Defaults to current project",
"type": "number"
"type": "integer"
}
},
"required": ["kind"],
Expand Down
18 changes: 16 additions & 2 deletions frontend/src/queries/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ export interface EventsNode extends EntityNode {
kind: NodeKind.EventsNode
/** The event or `null` for all events. */
event?: string | null
/** @asType integer */
limit?: number
/** Columns to order by */
orderBy?: string[]
Expand All @@ -267,6 +268,7 @@ export interface EventsNode extends EntityNode {

export interface ActionsNode extends EntityNode {
kind: NodeKind.ActionsNode
/** @asType integer */
id: number
}

Expand Down Expand Up @@ -339,13 +341,16 @@ export interface EventsQuery extends DataNode {
export interface PersonsNode extends DataNode {
kind: NodeKind.PersonsNode
search?: string
/** @asType integer */
cohort?: number
distinctId?: string
/** Properties configurable in the interface */
properties?: AnyPropertyFilter[]
/** Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person) */
fixedProperties?: AnyPropertyFilter[]
/** @asType integer */
limit?: number
/** @asType integer */
offset?: number
}

Expand Down Expand Up @@ -891,7 +896,10 @@ export interface TimeToSeeDataSessionsQuery extends DataNode {
/** Date range for the query */
dateRange?: DateRange

/** Project to filter on. Defaults to current project */
/**
* Project to filter on. Defaults to current project
* @asType integer
*/
teamId?: number

response?: TimeToSeeDataSessionsQueryResponse
Expand All @@ -914,7 +922,10 @@ export interface DatabaseSchemaQuery extends DataNode {
export interface TimeToSeeDataQuery extends DataNode {
kind: NodeKind.TimeToSeeDataQuery

/** Project to filter on. Defaults to current project */
/**
* Project to filter on. Defaults to current project
* @asType integer
*/
teamId?: number

/** Project to filter on. Defaults to current session */
Expand Down Expand Up @@ -949,11 +960,14 @@ export interface DateRange {
export interface BreakdownFilter {
// TODO: unclutter
breakdown_type?: BreakdownType | null
/** @asType integer */
breakdown_limit?: number
breakdown?: BreakdownKeyType
breakdown_normalize_url?: boolean
breakdowns?: Breakdown[]
/** @asType integer */
breakdown_group_type_index?: number | null
/** @asType integer */
breakdown_histogram_bin_count?: number // trends breakdown histogram bin count
breakdown_hide_other_aggregation?: boolean | null // hides the "other" field for trends
}
Expand Down
2 changes: 0 additions & 2 deletions mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ posthog/hogql/query.py:0: error: Argument 1 to "get_default_limit_for_context" h
posthog/hogql/query.py:0: error: "SelectQuery" has no attribute "select_queries" [attr-defined]
posthog/hogql/query.py:0: error: Subclass of "SelectQuery" and "SelectUnionQuery" cannot exist: would have incompatible method signatures [unreachable]
posthog/hogql_queries/query_runner.py:0: error: Incompatible types in assignment (expression has type "HogQLQuery | TrendsQuery | LifecycleQuery | InsightActorsQuery | EventsQuery | ActorsQuery | RetentionQuery | SessionsTimelineQuery | WebOverviewQuery | WebTopClicksQuery | WebStatsTableQuery | StickinessQuery | BaseModel | dict[str, Any]", variable has type "HogQLQuery | TrendsQuery | LifecycleQuery | InsightActorsQuery | EventsQuery | ActorsQuery | RetentionQuery | SessionsTimelineQuery | WebOverviewQuery | WebTopClicksQuery | WebStatsTableQuery | StickinessQuery") [assignment]
posthog/hogql_queries/insights/trends/breakdown_values.py:0: error: Incompatible types in assignment (expression has type "float | int", variable has type "int") [assignment]
posthog/hogql_queries/insights/trends/breakdown_values.py:0: error: Item "SelectUnionQuery" of "SelectQuery | SelectUnionQuery" has no attribute "select" [union-attr]
posthog/hogql_queries/insights/trends/breakdown_values.py:0: error: Value of type "list[Any] | None" is not indexable [index]
posthog/hogql_queries/sessions_timeline_query_runner.py:0: error: Statement is unreachable [unreachable]
Expand Down Expand Up @@ -433,7 +432,6 @@ posthog/hogql_queries/insights/trends/trends_query_runner.py:0: error: Item "Non
posthog/hogql_queries/insights/trends/trends_query_runner.py:0: error: Item "None" of "BreakdownFilter | None" has no attribute "breakdown" [union-attr]
posthog/hogql_queries/insights/trends/trends_query_runner.py:0: error: Argument 1 to "_event_property" of "TrendsQueryRunner" has incompatible type "str | float | list[str | float] | Any | None"; expected "str" [arg-type]
posthog/hogql_queries/insights/trends/trends_query_runner.py:0: error: Item "None" of "BreakdownFilter | None" has no attribute "breakdown_group_type_index" [union-attr]
posthog/hogql_queries/insights/trends/trends_query_runner.py:0: error: Argument 3 to "_event_property" of "TrendsQueryRunner" has incompatible type "float | Any | None"; expected "int | None" [arg-type]
posthog/hogql_queries/insights/retention_query_runner.py:0: error: Incompatible types in assignment (expression has type "Expr", variable has type "Call") [assignment]
posthog/hogql_queries/insights/retention_query_runner.py:0: error: Incompatible types in assignment (expression has type "Call", variable has type "Field") [assignment]
posthog/hogql_queries/insights/retention_query_runner.py:0: error: Argument "select" to "SelectQuery" has incompatible type "list[Alias]"; expected "list[Expr]" [arg-type]
Expand Down
8 changes: 4 additions & 4 deletions posthog/hogql_queries/insights/trends/breakdown_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BreakdownValues:
histogram_bin_count: Optional[int]
group_type_index: Optional[int]
hide_other_aggregation: Optional[bool]
breakdown_limit: Optional[float]
breakdown_limit: Optional[int]

def __init__(
self,
Expand All @@ -36,10 +36,10 @@ def __init__(
breakdown_type: str,
events_filter: ast.Expr,
chart_display_type: ChartDisplayType,
histogram_bin_count: Optional[float] = None,
group_type_index: Optional[float] = None,
histogram_bin_count: Optional[int] = None,
group_type_index: Optional[int] = None,
hide_other_aggregation: Optional[bool] = False,
breakdown_limit: Optional[float] = None,
breakdown_limit: Optional[int] = None,
):
self.team = team
self.event_name = event_name
Expand Down
20 changes: 10 additions & 10 deletions posthog/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ class TimeToSeeDataQuery(BaseModel):
sessionStart: Optional[str] = Field(
default=None, description="Session start time. Defaults to current time - 2 hours"
)
teamId: Optional[float] = Field(default=None, description="Project to filter on. Defaults to current project")
teamId: Optional[int] = Field(default=None, description="Project to filter on. Defaults to current project")


class TimeToSeeDataSessionsQueryResponse(BaseModel):
Expand Down Expand Up @@ -829,10 +829,10 @@ class BreakdownFilter(BaseModel):
extra="forbid",
)
breakdown: Optional[Union[str, float, List[Union[str, float]]]] = None
breakdown_group_type_index: Optional[float] = None
breakdown_group_type_index: Optional[int] = None
breakdown_hide_other_aggregation: Optional[bool] = None
breakdown_histogram_bin_count: Optional[float] = None
breakdown_limit: Optional[float] = None
breakdown_histogram_bin_count: Optional[int] = None
breakdown_limit: Optional[int] = None
breakdown_normalize_url: Optional[bool] = None
breakdown_type: Optional[BreakdownType] = None
breakdowns: Optional[List[Breakdown]] = None
Expand Down Expand Up @@ -1230,7 +1230,7 @@ class TimeToSeeDataSessionsQuery(BaseModel):
dateRange: Optional[DateRange] = Field(default=None, description="Date range for the query")
kind: Literal["TimeToSeeDataSessionsQuery"] = "TimeToSeeDataSessionsQuery"
response: Optional[TimeToSeeDataSessionsQueryResponse] = Field(default=None, description="Cached query response")
teamId: Optional[float] = Field(default=None, description="Project to filter on. Defaults to current project")
teamId: Optional[int] = Field(default=None, description="Project to filter on. Defaults to current project")


class WebAnalyticsQueryBase(BaseModel):
Expand Down Expand Up @@ -1396,7 +1396,7 @@ class EventsNode(BaseModel):
description="Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person)",
)
kind: Literal["EventsNode"] = "EventsNode"
limit: Optional[float] = None
limit: Optional[int] = None
math: Optional[
Union[BaseMathType, PropertyMathType, CountPerActorMathType, Literal["unique_group"], Literal["hogql"]]
] = None
Expand Down Expand Up @@ -1525,7 +1525,7 @@ class PersonsNode(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
cohort: Optional[float] = None
cohort: Optional[int] = None
distinctId: Optional[str] = None
fixedProperties: Optional[
List[
Expand All @@ -1547,8 +1547,8 @@ class PersonsNode(BaseModel):
description="Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person)",
)
kind: Literal["PersonsNode"] = "PersonsNode"
limit: Optional[float] = None
offset: Optional[float] = None
limit: Optional[int] = None
offset: Optional[int] = None
properties: Optional[
List[
Union[
Expand Down Expand Up @@ -1692,7 +1692,7 @@ class ActionsNode(BaseModel):
default=None,
description="Fixed properties in the query, can't be edited in the interface (e.g. scoping down by person)",
)
id: float
id: int
kind: Literal["ActionsNode"] = "ActionsNode"
math: Optional[
Union[BaseMathType, PropertyMathType, CountPerActorMathType, Literal["unique_group"], Literal["hogql"]]
Expand Down

0 comments on commit 4c9977b

Please sign in to comment.