mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #26120 -- Made HStoreField cast keys and values to strings.
HStoreField now converts all keys and values to string before they're saved to the database.
This commit is contained in:
parent
93897a6a75
commit
8dea9f089d
3 changed files with 36 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from django.core import exceptions, serializers
|
||||
|
@ -37,6 +40,20 @@ class SimpleTests(PostgreSQLTestCase):
|
|||
reloaded = HStoreModel.objects.get()
|
||||
self.assertEqual(reloaded.field, value)
|
||||
|
||||
def test_key_val_cast_to_string(self):
|
||||
value = {'a': 1, 'b': 'B', 2: 'c', 'ï': 'ê', b'x': b'test'}
|
||||
expected_value = {'a': '1', 'b': 'B', '2': 'c', 'ï': 'ê', 'x': 'test'}
|
||||
|
||||
instance = HStoreModel.objects.create(field=value)
|
||||
instance = HStoreModel.objects.get()
|
||||
self.assertDictEqual(instance.field, expected_value)
|
||||
|
||||
instance = HStoreModel.objects.get(field__a=1)
|
||||
self.assertDictEqual(instance.field, expected_value)
|
||||
|
||||
instance = HStoreModel.objects.get(field__has_keys=[2, 'a', 'ï'])
|
||||
self.assertDictEqual(instance.field, expected_value)
|
||||
|
||||
|
||||
class TestQuerying(PostgreSQLTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue