Skip to content

Commit

Permalink
[app][fix] yield if record serializationfails
Browse files Browse the repository at this point in the history
  • Loading branch information
M3ssman committed Oct 11, 2024
1 parent 960f3da commit cf74530
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "digiflow"
version = "5.4.6"
version = "5.4.7"
description = "Father's Little Digitization Workflow Helper"
readme = "README.md"
requires-python = ">=3.8"
Expand Down
13 changes: 11 additions & 2 deletions src/digiflow/record/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Common record attributes"""

import ast
import json
import time
import typing

Expand Down Expand Up @@ -122,14 +123,22 @@ def parse(input_data):

def dict(self, dict_map=None) -> typing.Dict:
"""Serialize Record into Python dict
as input for JSON load
as input for JSON load.
Please note: Tries to dump deep structures
and yields exception if record unlikely
to be JSON serializable
"""
as_dict = {}
if dict_map is None:
dict_map = DEFAULT_MAPPINGS
for label, field in dict_map.items():
if hasattr(self, label):
as_dict[field] = getattr(self, label)
try:
json.dumps(as_dict)
except TypeError as struct_err:
err_msg = f"{struct_err.args[0]} => {self.info}"
raise RecordDataException(err_msg) from struct_err
return as_dict

@property
Expand Down Expand Up @@ -171,7 +180,7 @@ def info(self, any_value):
self._info.update(any_value)
elif isinstance(self._info, tuple):
self._info[-1].update(any_value)
except (AttributeError,SyntaxError, ValueError):
except (AttributeError, SyntaxError, ValueError):
self._info = any_value


Expand Down

0 comments on commit cf74530

Please sign in to comment.