Skip to content

Commit

Permalink
fixed bug whereby null values for list-valued column were not properl…
Browse files Browse the repository at this point in the history
…y read from the sqlite db
  • Loading branch information
xrotwang committed Jan 15, 2024
1 parent 12c9631 commit c796e4f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

Unreleased
----------

- Fixed handling of null values for list-valued columns when reading from sqlite db.



Version 3.2.2
-------------

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ source =

[coverage:report]
show_missing = true
skip_covered = true

[tox:tox]
envlist = py38, py39, py310, py311, py312
Expand Down
4 changes: 3 additions & 1 deletion src/csvw/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,9 @@ def read(self) -> typing.Dict[str, typing.List[typing.OrderedDict]]:
d = collections.OrderedDict()
for k, v in zip(cols, row):
if k in seps:
if not v:
if v is None:
d[k] = None
elif not v:
d[k] = []
elif seps[k] == 'json':
d[k] = json.loads(v)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ def test_list_valued_non_text(tg, translate):
tg.tables[0].tableSchema.columns.append(Column.fromvalue(
{'separator': '#', 'name': 'v', 'datatype': 'integer'}))
db = Database(tg, translate=translate)
db.write(data=[{'v': [1, 2, 3]}])
db.write(data=[{'v': [1, 2, 3]}, {'v': None}])
data = db.read()['data']
assert data[0]['vv'] == [1, 2, 3]
assert data[1]['vv'] is None


def test_required(tg):
Expand Down

0 comments on commit c796e4f

Please sign in to comment.