BE: FREEBOX dual stack IP fix #1804

This commit is contained in:
jokob-sk committed 2026-09-23 08:17:23 +10:00
1 parent 24301cbdbc
commit 7aca7c17f3
5 files changed
+106 -8

No files matched your search

+15 -1
View File
@@ -45,6 +45,20 @@ folder = apiPath
# string, which mixed_type_sort_key sorts numerically on its own.
_IP_SORT_FIELDS = {"devLastIP", "devPrimaryIPv4", "devPrimaryIPv6"}
def _ip_sort_key(value):
"""Sort key for an IP-address field: (0, long_value) for a real address,
(1, 0) for empty/unparseable - mirrors mixed_type_sort_key's bucketing
(valid values sort before the empty bucket in ascending order, and Python's
sorted(reverse=True) flips both together) instead of relying on
format_ip_long's -1 sentinel, which put blanks *before* real addresses in
ascending order - the opposite of every other column's convention."""
long_value = format_ip_long(value) if value else -1
if long_value < 0:
return (1, 0)
return (0, long_value)
# In-memory cache for lang strings
_langstrings_cache = {} # caches lists per file (core JSON or plugin)
_langstrings_cache_mtime = {} # tracks last modified times
@@ -403,7 +417,7 @@ class Query(ObjectType):
# Numeric sort so e.g. 192.168.1.15 sorts before 192.168.1.105
devices_data = sorted(
devices_data,
key=lambda x: format_ip_long(x.get(field) or ""),
key=lambda x: _ip_sort_key(x.get(field)),
reverse=(sort_option.order.lower() == "desc"),
)
else: