Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimulationConfig ValidationError with jsonschema 4.6.0 #241

Closed
emollier opened this issue Jul 17, 2022 · 1 comment
Closed

SimulationConfig ValidationError with jsonschema 4.6.0 #241

emollier opened this issue Jul 17, 2022 · 1 comment

Comments

@emollier
Copy link

Greetings,

As reported initially by Thomas Goirand in Debian Bug#1015011, the test suite of bmtk fails with the error message below when the version of the Python module jsonschema is bumped to version 4:

--- Logging error ---
Traceback (most recent call last):
  File "/<<PKGBUILDDIR>>/bmtk/simulator/core/simulation_config.py", line 67, in validate
    return super(SimulationConfig, self).validate()
  File "/<<PKGBUILDDIR>>/bmtk/utils/sonata/config/sonata_config.py", line 145, in validate
    self.validator.validate(self)
  File "/<<PKGBUILDDIR>>/bmtk/simulator/core/simulation_config.py", line 61, in validator
    self._validator = SimulationConfigValidator(schema=config_schema)
  File "/<<PKGBUILDDIR>>/bmtk/simulator/core/simulation_config_validator.py", line 41, in __init__
    super(SimulationConfigValidator, self).__init__(schema, types, resolver, format_checker)
TypeError: create.<locals>.Validator.__init__() takes from 2 to 4 positional arguments but 5 were given

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.10/logging/__init__.py", line 1103, in emit
    stream.write(msg + self.terminator)
ValueError: I/O operation on closed file.
Call stack:
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/pytest/__main__.py", line 5, in <module>
    raise SystemExit(pytest.console_main())
  File "/usr/lib/python3/dist-packages/_pytest/config/__init__.py", line 187, in console_main
    code = main()
  File "/usr/lib/python3/dist-packages/_pytest/config/__init__.py", line 164, in main
    ret: Union[ExitCode, int] = config.hook.pytest_cmdline_main(
  File "/usr/lib/python3/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 315, in pytest_cmdline_main
    return wrap_session(config, _main)
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 268, in wrap_session
    session.exitstatus = doit(config, session) or 0
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 322, in _main
    config.hook.pytest_runtestloop(session=session)
  File "/usr/lib/python3/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/main.py", line 347, in pytest_runtestloop
    item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem)
  File "/usr/lib/python3/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 111, in pytest_runtest_protocol
    runtestprotocol(item, nextitem=nextitem)
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 130, in runtestprotocol
    reports.append(call_and_report(item, "call", log))
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 219, in call_and_report
    call = call_runtest_hook(item, when, **kwds)
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 258, in call_runtest_hook
    return CallInfo.from_call(
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 338, in from_call
    result: Optional[TResult] = func()
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 259, in <lambda>
    lambda: ihook(item=item, **kwds), when=when, reraise=reraise
  File "/usr/lib/python3/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/runner.py", line 166, in pytest_runtest_call
    item.runtest()
  File "/usr/lib/python3/dist-packages/_pytest/python.py", line 1761, in runtest
    self.ihook.pytest_pyfunc_call(pyfuncitem=self)
  File "/usr/lib/python3/dist-packages/pluggy/_hooks.py", line 265, in __call__
    return self._hookexec(self.name, self.get_hookimpls(), kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_manager.py", line 80, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "/usr/lib/python3/dist-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python3/dist-packages/_pytest/python.py", line 192, in pytest_pyfunc_call
    result = testfunction(**testargs)
  File "/<<PKGBUILDDIR>>/bmtk/tests/simulator/core/test_simulation_config_validator.py", line 23, in test_validate_network
    assert(cfg.validate())
  File "/<<PKGBUILDDIR>>/bmtk/simulator/core/simulation_config.py", line 71, in validate
    self.io.log_exception(msg)
  File "/<<PKGBUILDDIR>>/bmtk/simulator/core/io_tools.py", line 122, in log_exception
    self.logger.error(message)
Message: 'SimulationConfig ValidationError: create.<locals>.Validator.__init__() takes from 2 to 4 positional arguments but 5 were given'
Arguments: ()

This has been tested with python3 3.9.13 and 3.10.5. Affected jsonschema module version is 4.6.0, the former 3.2.0 is the last know version to not raise that issue. To reproduce the issue, simply run the test suite:

$ python3 -m pytest bmtk/tests/

The patch below seems to at least work around the problem:

--- a/bmtk/simulator/core/simulation_config_validator.py
+++ b/bmtk/simulator/core/simulation_config_validator.py
@@ -37,8 +37,8 @@
         validator.validate(file.json)
     """
 
-    def __init__(self, schema, types=(), resolver=None, format_checker=None, file_formats=()):
-        super(SimulationConfigValidator, self).__init__(schema, types, resolver, format_checker)
+    def __init__(self, schema, resolver=None, format_checker=None, file_formats=()):
+        super(SimulationConfigValidator, self).__init__(schema, resolver, format_checker)
 
         # custom parameter
         self.VALIDATORS["exists"] = self._check_path

When strolling through the jsonschema source code, I stumbled upon a statement that a default_types parameter was deprecated in version 3 and type_checker should be prefered; default_types has then been removed in version 4, so maybe this is relevant?

Have a nice day, :)
Étienne.

@emollier
Copy link
Author

Hmm, nevermind that; I was testing agains bmtk 1.0.5, but this looks to be already addressed in the develop branch with the same approach apparently.

Sorry for the noise... ^_^"
Étienne.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant