Skip to content

Commit

Permalink
fix(data-warehouse): Dont throw when updating incremental value with …
Browse files Browse the repository at this point in the history
…an empty table (#27218)
  • Loading branch information
Gilbert09 authored Jan 2, 2025
1 parent d74c8f7 commit 83a07c1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 0 additions & 2 deletions mypy-baseline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict ent
posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict entry 0 has incompatible type "str": "PathsFilter"; expected "str": "TrendsFilter" [dict-item]
posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict entry 0 has incompatible type "str": "LifecycleFilter"; expected "str": "TrendsFilter" [dict-item]
posthog/hogql_queries/legacy_compatibility/filter_to_query.py:0: error: Dict entry 0 has incompatible type "str": "StickinessFilter"; expected "str": "TrendsFilter" [dict-item]
posthog/warehouse/models/external_data_schema.py:0: error: Incompatible types in assignment (expression has type "str", variable has type "int | float") [assignment]
posthog/warehouse/models/external_data_schema.py:0: error: Incompatible types in assignment (expression has type "str", variable has type "int | float") [assignment]
posthog/session_recordings/models/session_recording.py:0: error: Argument "distinct_id" to "MissingPerson" has incompatible type "str | None"; expected "str" [arg-type]
posthog/session_recordings/models/session_recording.py:0: error: Incompatible type for lookup 'persondistinctid__team_id': (got "Team", expected "str | int") [misc]
posthog/models/hog_functions/hog_function.py:0: error: Argument 1 to "get" of "dict" has incompatible type "str | None"; expected "str" [arg-type]
Expand Down
6 changes: 6 additions & 0 deletions posthog/temporal/data_imports/pipelines/pipeline_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ def save_last_incremental_value(schema_id: str, team_id: str, source: DltSource,

logger.debug(f"Updating incremental_field_last_value with {last_value}")

if last_value is None:
logger.debug(
f"Incremental value is None. This could mean the table has zero rows. Full incremental object: {incremental_object}"
)
return

schema.update_incremental_field_last_value(last_value)


Expand Down
14 changes: 13 additions & 1 deletion posthog/warehouse/models/external_data_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ def update_incremental_field_last_value(self, last_value: Any) -> None:
incremental_field_type = self.sync_type_config.get("incremental_field_type")

last_value_py = last_value.item() if isinstance(last_value, numpy.generic) else last_value
last_value_json: Any

if last_value_py is None:
return

if (
incremental_field_type == IncrementalFieldType.Integer
Expand All @@ -85,9 +89,17 @@ def update_incremental_field_last_value(self, last_value: Any) -> None:
if isinstance(last_value_py, int | float):
last_value_json = last_value_py
elif isinstance(last_value_py, datetime):
last_value_json = str(last_value_py)
last_value_json = last_value_py.isoformat()
else:
last_value_json = int(last_value_py)
elif (
incremental_field_type == IncrementalFieldType.DateTime
or incremental_field_type == IncrementalFieldType.Timestamp
):
if isinstance(last_value_py, datetime):
last_value_json = last_value_py.isoformat()
else:
last_value_json = str(last_value_py)
else:
last_value_json = str(last_value_py)

Expand Down

0 comments on commit 83a07c1

Please sign in to comment.