fix: preserve numeric-shaped docnames without losing JSON parsing of scalars
This commit is contained in:
parent
470964015e
commit
8ade4ce27d
2 changed files with 13 additions and 7 deletions
|
|
@ -366,6 +366,9 @@ class TestFilters(IntegrationTestCase):
|
||||||
self.assertEqual(get_safe_filters('[["name", "=", "ABC"]]'), [["name", "=", "ABC"]])
|
self.assertEqual(get_safe_filters('[["name", "=", "ABC"]]'), [["name", "=", "ABC"]])
|
||||||
# FrappeClient encodes scalar filters via frappe.as_json — must still unwrap
|
# FrappeClient encodes scalar filters via frappe.as_json — must still unwrap
|
||||||
self.assertEqual(get_safe_filters('"ABC"'), "ABC")
|
self.assertEqual(get_safe_filters('"ABC"'), "ABC")
|
||||||
|
self.assertIsNone(get_safe_filters("null"))
|
||||||
|
self.assertIs(get_safe_filters("true"), True)
|
||||||
|
self.assertIs(get_safe_filters("false"), False)
|
||||||
|
|
||||||
def test_get_safe_filters_passes_through_non_strings(self):
|
def test_get_safe_filters_passes_through_non_strings(self):
|
||||||
self.assertEqual(get_safe_filters({"name": "ABC"}), {"name": "ABC"})
|
self.assertEqual(get_safe_filters({"name": "ABC"}), {"name": "ABC"})
|
||||||
|
|
|
||||||
|
|
@ -904,13 +904,16 @@ def call(fn, *args, **kwargs):
|
||||||
|
|
||||||
|
|
||||||
def get_safe_filters(filters):
|
def get_safe_filters(filters):
|
||||||
if isinstance(filters, str) and filters and filters[0] in '{["':
|
|
||||||
try:
|
try:
|
||||||
return orjson.loads(filters)
|
parsed = orjson.loads(filters)
|
||||||
except (TypeError, ValueError):
|
except (TypeError, ValueError):
|
||||||
# filters are not passed, not json
|
# not a string, or not valid json
|
||||||
pass
|
|
||||||
return filters
|
return filters
|
||||||
|
# numeric JSON is ambiguous: docnames like "3E002" parse as floats and
|
||||||
|
# would be corrupted by stringifying back, so keep the original string
|
||||||
|
if isinstance(parsed, int | float) and not isinstance(parsed, bool):
|
||||||
|
return filters
|
||||||
|
return parsed
|
||||||
|
|
||||||
|
|
||||||
def create_batch(iterable: Iterable, size: int) -> Generator[Iterable]:
|
def create_batch(iterable: Iterable, size: int) -> Generator[Iterable]:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue