Skip to content

Commit

Permalink
history: check for null values during database migration
Browse files Browse the repository at this point in the history
Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed Jun 2, 2024
1 parent 4fe89d5 commit f2f2c93
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions moonraker/components/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ class HistorySqlDefinition(SqlTableDefinition):
)
version = 1

def _get_entry_item(
self, entry: Dict[str, Any], name: str, default: Any = 0.
) -> Any:
val = entry.get(name)
if val is None:
return default
return val

def migrate(self, last_version: int, db_provider: DBProviderWrapper) -> None:
if last_version == 0:
conn = db_provider.connection
Expand All @@ -155,16 +163,16 @@ def migrate(self, last_version: int, db_provider: DBProviderWrapper) -> None:
conv_vals.append(
(
None,
entry.get("user", "No User"),
entry["filename"],
entry["status"],
entry["start_time"],
entry["end_time"],
entry["print_duration"],
entry["total_duration"],
entry["filament_used"],
entry["metadata"],
entry.get("auxiliary_data", []),
self._get_entry_item(entry, "user", "No User"),
self._get_entry_item(entry, "filename"),
self._get_entry_item(entry, "status", "error"),
self._get_entry_item(entry, "start_time"),
self._get_entry_item(entry, "end_time"),
self._get_entry_item(entry, "print_duration"),
self._get_entry_item(entry, "total_duration"),
self._get_entry_item(entry, "filament_used"),
self._get_entry_item(entry, "metadata", {}),
self._get_entry_item(entry, "auxiliary_data", []),
"default"
)
)
Expand Down Expand Up @@ -617,7 +625,7 @@ def finish(self,
print_stats: Dict[str, Any] = {}
) -> None:
self.end_time = time.time()
self.status = status
self.status = status if status is not None else "error"
self.update_from_ps(print_stats)

def get(self, name: str) -> Any:
Expand All @@ -638,7 +646,7 @@ def set_aux_data(self, fields: List[HistoryFieldData]) -> None:

def update_from_ps(self, data: Dict[str, Any]) -> None:
for i in data:
if hasattr(self, i):
if hasattr(self, i) and data[i] is not None:
setattr(self, i, data[i])


Expand Down

0 comments on commit f2f2c93

Please sign in to comment.