File "/home/ubuntu/grafana-agent-operator/lib/charms/grafana_agent/v0/cos_agent.py", line 333, in <module>
if int(pydantic.version.VERSION.split(".")[0]) < 2: # type: ignore
AttributeError: module 'pydantic.v1' has no attribute 'version'
Solution
Remove conditional import of pydantic.v1 and adjust the models instead to support both Pydantic versions.
Context
Testing Instructions
Run tox -r on the current code
To check how it behaves with pydantic v2, unpin pydantic in requirements.txt and run tox -r again. One scenario test will be failing as it creates a raw model, other than that everything should still work.
Issue
After https://github.com/canonical/grafana-agent-operator/pull/156, changes in cos_agent done to support both pydantic versions fail with
Solution
Remove conditional import of
pydantic.v1
and adjust the models instead to support both Pydantic versions.Context
Testing Instructions
tox -r
on the current codetox -r
again. One scenario test will be failing as it creates a raw model, other than that everything should still work.Upgrade Notes