Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • xcg/odoo-modules/converter
1 result
Show changes
Commits on Source (2)
......@@ -6,3 +6,12 @@
TEST_OPTIONS: --test-tags=odoo_addons_mail
# Also install mail to run mail dependant tets
ODOO_SCRIPTS_MODULE_LIST: mail
mypy:
variables:
INSTALL_SECTION: "[test,schema-validation]"
test-schema-validation:
extends: test
variables:
INSTALL_SECTION: "[test,schema-validation]"
......@@ -32,3 +32,4 @@
0a3fa9ad94afaf928de060d3cb15e5ef96988d91 18.0.4.0.0
0de61891edacf2629b4aca660ae72d020f8edcf9 18.0.4.1.0
b4e27f823ace4a230c2cca4b0c95d6a4c8019b20 18.0.5.0.0
dd3bf0df6615bf036e21490a7c9a74f5d9d6199c 18.0.6.0.0
Changelog
=========
18.0.6.0.0
----------
fastjsonschema is now an optional dependency. It is listed in the dependencies of section *schema-validation*.
If validation needs to be done and the library is missing, an exception will be raised.
18.0.5.0.0
----------
......
......@@ -18,3 +18,5 @@
|maturity| |license| |ruff| |prettier|
Convert odoo records to/from plain data structures.
section *schema-validation* need to be installed if validation is needed.
......@@ -21,9 +21,9 @@
"name": "Converter",
"license": "AGPL-3",
"summary": "Convert odoo records to/from plain data structures.",
"version": "18.0.5.0.0",
"version": "18.0.6.0.0",
"category": "Hidden",
"author": "XCG Consulting",
"website": "https://orbeet.io/",
"depends": ["base"],
"installable": True,
......@@ -25,7 +25,6 @@
"category": "Hidden",
"author": "XCG Consulting",
"website": "https://orbeet.io/",
"depends": ["base"],
"installable": True,
"external_dependencies": {"python": ["fastjsonschema"]},
}
......@@ -23,7 +23,6 @@
from collections.abc import Iterable, Mapping
from typing import Any, Final
import fastjsonschema # type: ignore[import-untyped]
from odoo import _, api, models # type: ignore[import-untyped]
from odoo.exceptions import UserError # type: ignore[import-untyped]
......@@ -39,6 +38,14 @@
)
from .validate import NotInitialized, Validation, Validator
try:
from fastjsonschema import JsonSchemaException # type: ignore[import-untyped]
except ImportError:
# Ignore no-redef, added for compatibility
class JsonSchemaException(Exception): # type: ignore[no-redef]
"""Custom error in case of missing optional requirement"""
_logger = logging.getLogger(__name__)
......@@ -129,7 +136,7 @@
if self.validator:
try:
self.validator.validate(self._jsonschema, message_data)
except (NotInitialized, fastjsonschema.JsonSchemaException):
except (NotInitialized, JsonSchemaException):
_logger.warning("Validation failed", exc_info=True)
if self.validation == Validation.STRICT:
raise
......@@ -152,7 +159,7 @@
if self.validator:
try:
self.validator.validate(self._jsonschema, message_value)
except (NotInitialized, fastjsonschema.JsonSchemaException):
except (NotInitialized, JsonSchemaException):
_logger.warning("Validation failed", exc_info=True)
if self.validation == Validation.STRICT:
raise
......
......@@ -15,6 +15,6 @@
"Framework :: Odoo :: 18.0",
"License :: OSI Approved :: GNU Affero General Public License v3",
]
dependencies = ["odoo==18.0.*", "fastjsonschema"]
dependencies = ["odoo==18.0.*"]
[project.optional-dependencies]
......@@ -19,5 +19,6 @@
[project.optional-dependencies]
schema-validation = ["fastjsonschema"]
doc = ["sphinx"]
test = []
......
......@@ -18,9 +18,10 @@
#
##############################################################################
import json
from unittest import skipUnless
from odoo import tests # type: ignore[import-untyped]
from ..validate import Validator
......@@ -21,9 +22,10 @@
from odoo import tests # type: ignore[import-untyped]
from ..validate import Validator
@skipUnless(tests.can_import("fastjsonschema"), "fastjsonschema module not available")
class TestValidate(tests.TransactionCase):
def test_validate(self):
validator = Validator(
......
......@@ -25,6 +25,5 @@
from importlib import import_module
from typing import Any, LiteralString
import fastjsonschema # type: ignore[import-untyped]
from odoo.exceptions import UserError # type: ignore[import-untyped]
......@@ -29,5 +28,12 @@
from odoo.exceptions import UserError # type: ignore[import-untyped]
_fastjsonschema: None | Exception = None
try:
import fastjsonschema # type: ignore[import-untyped]
except ImportError as e:
_fastjsonschema = e
_logger = logging.getLogger(__name__)
......@@ -101,6 +107,8 @@
# Prepare validators for each schema. We add an HTTPS handler that
# points back to our schema definition cache built above.
for schema_id, schema in schemas.items():
if _fastjsonschema is not None:
raise _fastjsonschema
self.validators[schema_id] = fastjsonschema.compile(
schema,
handlers={"https": lambda uri: schemas[uri]},
......