Skip to content
Snippets Groups Projects
Commit 732a3f95 authored by Erwan Rouchet's avatar Erwan Rouchet Committed by Bastien Abadie
Browse files

Handle Decimal values when saving rows to SQLite databases

parent a6506333
No related branches found
No related tags found
1 merge request!1798Handle Decimal values when saving rows to SQLite databases
......@@ -51,7 +51,7 @@ backend-tests:
stage: test
services:
- name: postgis/postgis:12-3.1
- name: postgis/postgis:14-3.2
alias: postgres
artifacts:
......
......@@ -5,6 +5,7 @@ import sqlite3
import tempfile
import uuid
from datetime import datetime, timezone
from decimal import Decimal
from pathlib import Path
from django.conf import settings
......@@ -70,6 +71,15 @@ def save_sqlite(rows, table, cursor):
if isinstance(value, (list, dict)):
return json.dumps(value)
# Serialize Decimal numbers as regular floats
# We don't care about any loss of precision because SQLite will loose that precision anyway
if isinstance(value, Decimal):
return float(value)
# Show very explicit error messages if we stumble upon an unexpected type
# https://docs.python.org/3.8/library/sqlite3.html#sqlite-and-python-types
assert value is None or isinstance(value, (int, float, str, bytes)), f'Type {type(value)} is not supported by sqlite3'
return value
rows = [
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment