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 error using cos_agent in a machine charm #151

Open
erik78se opened this issue May 25, 2024 · 3 comments
Open

Pydantic error using cos_agent in a machine charm #151

erik78se opened this issue May 25, 2024 · 3 comments

Comments

@erik78se
Copy link

I'm going through some code I've made some time ago to test the COS lite with machine charms.

https://github.com/erik78se/juju-operators-examples/tree/main/observed

After upgrading a previous build charm, using the cos_agent interface https://canonical.github.io/charm-relation-interfaces/interfaces/cos_agent/v0/

I strike an ERROR in the upgrade-hook.

unit-observed-1: 16:44:51 WARNING unit.observed/1.upgrade-charm If you got this error by calling handler() within __get_pydantic_core_schema__ then you likely need to call handler.generate_schema(<some type>) since we do not call __get_pydantic_core_schema__ on <some type> otherwise to avoid infinite recursion.

Is this an error or am I doing something wrong?

@erik78se
Copy link
Author

Also, in the error logs there is this message:

"unit-observed-1: 17:04:08 WARNING unit.observed/1.upgrade-charm pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'cosl.grafana_dashboard.GrafanaDashboard'>. Set arbitrary_types_allowed=True in the model_config to ignore this error or implement __get_pydantic_core_schema__ on your type to fully support it."

I set the suggested value:

juju model-config arbitrary_types_allowed=true
juju resolved observed/0

But there is no resolution to the error.

@erik78se
Copy link
Author

Possibly, this is due to some of my grafana-dashboards not being "correct" ?

unit-observed-2: 17:33:11 WARNING unit.observed/2.install return self._model_schema(obj)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 580, in _model_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 580, in
unit-observed-2: 17:33:11 WARNING unit.observed/2.install {k: self._generate_md_field_schema(k, v, decorators) for k, v in fields.items()},
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 916, in _generate_md_field_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install common_field = self._common_field_schema(name, field_info, decorators)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 1081, in _common_field_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install schema = self._apply_annotations(
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 1820, in _apply_annotations
unit-observed-2: 17:33:11 WARNING unit.observed/2.install schema = get_inner_schema(source_type)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_schema_generation_shared.py", line 82, in call
unit-observed-2: 17:33:11 WARNING unit.observed/2.install schema = self._handler(source_type)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 1902, in new_handler
unit-observed-2: 17:33:11 WARNING unit.observed/2.install schema = metadata_get_schema(source, get_inner_schema)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_std_types_schema.py", line 314, in get_pydantic_core_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install items_schema = handler.generate_schema(self.item_source_type)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_schema_generation_shared.py", line 96, in generate_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install return self._generate_schema.generate_schema(source_type)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 502, in generate_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install schema = self._generate_schema_inner(obj)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 758, in _generate_schema_inner
unit-observed-2: 17:33:11 WARNING unit.observed/2.install return self.match_type(obj)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 844, in match_type
unit-observed-2: 17:33:11 WARNING unit.observed/2.install return self._unknown_type_schema(obj)
unit-observed-2: 17:33:11 WARNING unit.observed/2.install File "/var/lib/juju/agents/unit-observed-2/charm/venv/pydantic/_internal/_generate_schema.py", line 405, in _unknown_type_schema
unit-observed-2: 17:33:11 WARNING unit.observed/2.install raise PydanticSchemaGenerationError(
unit-observed-2: 17:33:11 WARNING unit.observed/2.install pydantic.errors.PydanticSchemaGenerationError: Unable to generate pydantic-core schema for <class 'cosl.grafana_dashboard.GrafanaDashboard'>. Set arbitrary_types_allowed=True in the model_config to ignore this error or implement __get_pydantic_core_schema__ on your type to fully support it.
unit-observed-2: 17:33:11 WARNING unit.observed/2.install
unit-observed-2: 17:33:11 WARNING unit.observed/2.install If you got this error by calling handler() within __get_pydantic_core_schema__ then you likely need to call handler.generate_schema(<some type>) since we do not call __get_pydantic_core_schema__ on <some type> otherwise to avoid infinite recursion.
unit-observed-2: 17:33:11 WARNING unit.observed/2.install
unit-observed-2: 17:33:11 WARNING unit.observed/2.install For further information visit https://errors.pydantic.dev/2.7/u/schema-for-unknown-type
unit-observed-2: 17:33:11 ERROR juju.worker.uniter.operation hook "install" (via hook dispatching script: dispatch) failed: exit status 1
unit-observed-2: 17:33:11 INFO juju.worker.uniter awaiting error resolution for "install" hook

@erik78se
Copy link
Author

erik78se commented May 27, 2024

I have found the issue resolution, which is that the requirements.txt for python needs to be pinning pydantic to < 2.

This is important information and even more important to perhaps get a fix for since this will hit anyone trying to use the lib.

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