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"]])
|
||||
# FrappeClient encodes scalar filters via frappe.as_json — must still unwrap
|
||||
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):
|
||||
self.assertEqual(get_safe_filters({"name": "ABC"}), {"name": "ABC"})
|
||||
|
|
|
|||
|
|
@ -904,13 +904,16 @@ def call(fn, *args, **kwargs):
|
|||
|
||||
|
||||
def get_safe_filters(filters):
|
||||
if isinstance(filters, str) and filters and filters[0] in '{["':
|
||||
try:
|
||||
return orjson.loads(filters)
|
||||
except (TypeError, ValueError):
|
||||
# filters are not passed, not json
|
||||
pass
|
||||
return filters
|
||||
try:
|
||||
parsed = orjson.loads(filters)
|
||||
except (TypeError, ValueError):
|
||||
# not a string, or not valid json
|
||||
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]:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue