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

Pydantic classes for model emulators are non JSON serializable #439

Open
1 task
Zeitsperre opened this issue Jan 15, 2025 · 1 comment
Open
1 task

Pydantic classes for model emulators are non JSON serializable #439

Zeitsperre opened this issue Jan 15, 2025 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Zeitsperre
Copy link
Member

Setup Information

  • ravenpy version: 0.16.1
  • Python version: Any
  • Operating System: openSUSE Tumbleweed x86_64

Description

This problem occurs when exposing the Emulator models in the generated documentation. The issue appears to be brought on because the ListCommand class can't serialize what root is when generating the documentation:

lass ListCommand(RootModel, _Command):
    """Use so that commands with __root__: Sequence[Command] behave like a list."""

    root: Sequence[Any]

    def __iter__(self):
        return iter(self.root)

    def __getitem__(self, item):
        return self.root[item]

    def __len__(self):
        return len(self.root)

    model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)

This means that any emulated models built using it are raising errors when trying to parse the documentation. I'm not familiar enough with pydantic to understand how to fix this, so I'm removing them from the docs to see if that fixes things.

The warnings summary:

/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.commands.SeasonalRelativeHeight' because the following pydantic fields can't be serialized properly: ['root'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.commands.SeasonalRelativeLAI' because the following pydantic fields can't be serialized properly: ['root'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.rvs.Config' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.rvs.RVP' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.BasicRoute' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.Blended' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.CanadianShield' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.GR4JCN' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.HBVEC' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.HMETS' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.HYPR' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.Mohyse' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.SACSMA' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.blended.Blended' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.canadianshield.CanadianShield' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.gr4jcn.GR4JCN' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.hbvec.HBVEC' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.hmets.HMETS' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.hypr.HYPR' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.mohyse.Mohyse' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.routing.BasicRoute' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].
/home/tjs/git/RavenPy/docs/autodoc_pydantic.rst: WARNING: JSON schema can't be generated for 'ravenpy.config.emulators.sacsma.SACSMA' because the following pydantic fields can't be serialized properly: ['seasonal_relative_lai', 'seasonal_relative_height'].

Steps To Reproduce

  1. Install autodoc-pydantic;
  2. Enable the sphinxcontrib-autodoc-pydantic extension in docs/conf.py;
  3. Add the imported models found in src/ravenpy/config/emulators/__init__.py to the __all__ listing;
  4. Run $ make docs.

Additional context

It could be the case that the magic methods for the underlying classes aren't written to support the data they might be initialized with (Sequence[Any] could be a lot of things)? I'm not sure.

Relevant resources:

Contribution

  • I would be willing/able to open a Pull Request to address this bug.
@Zeitsperre Zeitsperre added the bug Something isn't working label Jan 15, 2025
@Zeitsperre
Copy link
Member Author

Raised from discussion in #438

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants