canonical / grafana-agent-operator

https://charmhub.io/grafana-agent
Apache License 2.0
4 stars 11 forks source link

Fix pydantic models by dropping importing v1 #167

Closed mmkay closed 3 months ago

mmkay commented 3 months ago

Issue

After https://github.com/canonical/grafana-agent-operator/pull/156, changes in cos_agent done to support both pydantic versions fail with

  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

  1. Run tox -r on the current code
  2. 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.

Upgrade Notes