Skip to content

Commit 46a9b93

Browse files
phlogistonjohnmergify[bot]
authored andcommitted
sambacc: make config module robust to unexpected jsonschema versions
If jsonschema module doesn't understand our schemas then we assume that the version is too old and we should treat it the same as not having jsonschema installed. We recently found that having older jsonschema versions present in the container actually breaks sambacc. Because we prefer to install from rpm packages rather than pip in samba-container we ended up with older, and an untested version, of the library. This change tries to make the sambacc code more robust in that case. Signed-off-by: John Mulligan <[email protected]>
1 parent c81c65a commit 46a9b93

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

sambacc/config.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ class ValidationUnsupported(Exception):
5252
pass
5353

5454

55+
class _FakeRefResolutionError(Exception):
56+
pass
57+
58+
5559
def _schema_validate(data: dict[str, typing.Any], version: str) -> None:
5660
try:
5761
import jsonschema # type: ignore[import]
5862
except ImportError:
5963
raise ValidationUnsupported()
64+
try:
65+
_refreserror = getattr(jsonschema, "RefResolutionError")
66+
except AttributeError:
67+
_refreserror = _FakeRefResolutionError
6068

6169
global _JSON_SCHEMA
6270
if version == "v0" and version not in _JSON_SCHEMA:
@@ -66,7 +74,10 @@ def _schema_validate(data: dict[str, typing.Any], version: str) -> None:
6674
_JSON_SCHEMA[version] = sambacc.schema.conf_v0_schema.SCHEMA
6775
except ImportError:
6876
raise ValidationUnsupported()
69-
jsonschema.validate(instance=data, schema=_JSON_SCHEMA[version])
77+
try:
78+
jsonschema.validate(instance=data, schema=_JSON_SCHEMA[version])
79+
except _refreserror:
80+
raise ValidationUnsupported()
7081

7182

7283
def _check_config_version(data: JSONData) -> str:

0 commit comments

Comments
 (0)