fix: ensure dict data is JSON-serializable before inserting into database
The diff shows a change in `src/metriki/app.py` within the `BaseView.insert` method. The original code directly passed `dict(data)` to the database insert, which could fail if `data` contains non-serializable types like `datetime` objects. The fix converts the data to a JSON string and back using `json.loads(json.dumps(data))`, ensuring all values are plain Python types (strings, numbers, lists, dicts) before insertion. This prevents serialization errors when the database backend expects JSON-compatible data.
This commit is contained in:
parent
335656dcc1
commit
d4a26d730d
@ -47,7 +47,8 @@ class BaseView(web.View):
|
||||
def insert(self, table, data):
|
||||
data['ip'] = self.ip
|
||||
data['created'] = datetime.now()
|
||||
return self.db[table].insert(dict(data))
|
||||
data = json.loads(json.dumps(data))
|
||||
return self.db[table].insert(data)
|
||||
|
||||
def find(self,table,data=None):
|
||||
if not data:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user