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

Do not attempt to represent models due to non-serializable errors #438

Merged
merged 1 commit into from
Jan 15, 2025

Conversation

Zeitsperre
Copy link
Member

Pull Request Checklist:

  • This PR addresses an already opened issue (for bug fixes / features)
    • This PR fixes #xyz
  • (If applicable) Documentation has been added / updated (for bug fixes / features).
  • (If applicable) Tests have been added.
  • CHANGELOG.rst has been updated (with summary of main changes).
    • Link to issue (:issue:number) and pull request (:pull:number) has been added.

What kind of change does this PR introduce?

  • Removes the pydantic-defined models from the public API of emulators.

Does this PR introduce a breaking change?

No. Usage still works, but documentation should be different.

Other information:

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.

@Zeitsperre Zeitsperre requested a review from huard January 15, 2025 18:06
@coveralls
Copy link

Coverage Status

coverage: 81.292%. remained the same
when pulling 3b9dde4 on fix-docs-2
into 6bc470a on master.

@huard
Copy link
Collaborator

huard commented Jan 15, 2025

@Zeitsperre
Copy link
Member Author

Would https://sphinx-pydantic.readthedocs.io/en/latest/ help ?

It hasn't been updated in five years: https://github.com/Zsailer/sphinx-pydantic

On the other hand, there's https://github.com/mansenfranzen/autodoc_pydantic. This is currently disabled in RavenPy since it raises a bunch of errors when enabled and (you guessed it) it tries to generate the models:

/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'].
...

I'm wondering if 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)? Again, I'm not sure.

@Zeitsperre
Copy link
Member Author

Zeitsperre commented Jan 15, 2025

@huard
Copy link
Collaborator

huard commented Jan 15, 2025

Please open an issue so we come back to this later.

@Zeitsperre Zeitsperre merged commit df2ffed into master Jan 15, 2025
15 checks passed
@Zeitsperre Zeitsperre deleted the fix-docs-2 branch January 15, 2025 20:53
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

Successfully merging this pull request may close these issues.

3 participants