server.web.utils.json_compat

Utility functions for JSON compatibility between old and new client versions.

Attributes

JSON_COMPAT_CUTOFF_VERSION

Functions

normalize_node_ids(→ Optional[List[int]])

Normalize node_ids to a list of integers, supporting both old and new formats.

ensure_json_compatible_format(→ Any)

Ensure the node_ids are in a format that can be stored in the database.

_compare_versions(→ int)

Compare two version strings, handling dev versions.

get_client_compatibility_mode(→ str)

Determine the compatibility mode based on client version.

normalize_node_ids_for_client(→ Any)

Normalize node_ids based on client version compatibility.

Module Contents

server.web.utils.json_compat.JSON_COMPAT_CUTOFF_VERSION = '3.4.23'[source]
server.web.utils.json_compat.normalize_node_ids(node_ids: Any) List[int] | None[source]

Normalize node_ids to a list of integers, supporting both old and new formats.

Parameters:

node_ids – Can be: - None - A list of integers (new format) - A JSON string like “[1, 2, 3]” (old format) - A string representation of a list like “[1, 2, 3]”

Returns:

List of integers or None if input is None/empty

Raises:

ValueError – If the input cannot be parsed into a list of integers

server.web.utils.json_compat.ensure_json_compatible_format(node_ids: Any) Any[source]

Ensure the node_ids are in a format that can be stored in the database.

This function is used when storing data to ensure consistency.

Parameters:

node_ids – The node_ids to format

Returns:

The node_ids in a format suitable for database storage

server.web.utils.json_compat._compare_versions(version1: str, version2: str) int[source]

Compare two version strings, handling dev versions.

Parameters:
  • version1 – First version string (e.g., “3.4.23”, “3.4.24.dev1”)

  • version2 – Second version string (e.g., “3.4.24”)

Returns:

-1 if version1 < version2

0 if version1 == version2 1 if version1 > version2

server.web.utils.json_compat.get_client_compatibility_mode(client_version: str | None) str[source]

Determine the compatibility mode based on client version.

Parameters:

client_version – The client version string (e.g., “3.4.10”, “3.4.24.dev1”, “3.4.24.stage1”)

Returns:

“old”, “new”, or “unknown” - “new” for versions with “dev” or “stage” in them - “old” for versions <= JSON_COMPAT_CUTOFF_VERSION - “new” for versions > JSON_COMPAT_CUTOFF_VERSION

Return type:

Compatibility mode

server.web.utils.json_compat.normalize_node_ids_for_client(node_ids: Any, client_version: str | None = None) Any[source]

Normalize node_ids based on client version compatibility.

Parameters:
  • node_ids – The node_ids to normalize

  • client_version – The client version string

Returns:

  • For clients <= JSON_COMPAT_CUTOFF_VERSION: Returns quoted JSON string like “[1, 2]” (can be parsed with json.loads)

  • For clients > JSON_COMPAT_CUTOFF_VERSION: Returns unquoted JSON array like [1, 2]

Return type:

The node_ids in the format expected by the client