Skip to content

Commit 7b5bded

Browse files
committed
Fix bug in HStoreField string casting and add a test
1 parent 670d7d6 commit 7b5bded

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

psqlextra/fields/hstore_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ def get_prep_value(self, value):
4242
prep_value[key] = val
4343
elif val is not None:
4444
prep_value[key] = str(val)
45-
46-
prep_value[key] = val
45+
else:
46+
prep_value[key] = val
4747

4848
value = prep_value
4949

tests/test_hstore_field.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import pytest
2+
13
from psqlextra.fields import HStoreField
24

35

@@ -10,3 +12,17 @@ def test_deconstruct():
1012

1113
for key, value in original_kwargs.items():
1214
assert new_kwargs[key] == value
15+
16+
17+
@pytest.mark.parametrize('input,output', [
18+
(dict(key1=1, key2=2), dict(key1='1', key2='2')),
19+
(dict(key1='1', key2='2'), dict(key1='1', key2='2')),
20+
(dict(key1=1, key2=None, key3='3'), dict(key1='1', key2=None, key3='3')),
21+
([1, 2, 3], ['1', '2', '3']),
22+
(['1', '2', '3'], ['1', '2', '3']),
23+
])
24+
def test_get_prep_value(input, output):
25+
"""Tests whether the :see:HStoreField's get_prep_value
26+
method works properly."""
27+
28+
assert HStoreField().get_prep_value(input) == output

0 commit comments

Comments
 (0)