nautobot-app-circuit-maintenance
nautobot-app-circuit-maintenance copied to clipboard
Pydantic Errors on EmailSource and GmailAPI
Environment
- Python version: 3.8
- Nautobot version: 1.4.10
- nautobot-circuit-maintenance version: 1.0.0
Expected Behavior
Tests to run successfully upon initial clone of the repo.
Observed Behavior
It looks like pydantic doesn't like the unannotated field of emails_to_fetch
in the EmailSource
class and SCOPES
of the GmailAPI
.
File "/usr/local/lib/python3.8/site-packages/nautobot/extras/plugins/urls.py", line 32, in <module>
urlpatterns = import_object(f"{plugin_path}.urls.urlpatterns")
File "/usr/local/lib/python3.8/site-packages/nautobot/extras/plugins/utils.py", line 45, in import_object
spec.loader.exec_module(module)
File "/source/nautobot_circuit_maintenance/urls.py", line 5, in <module>
from . import views
File "/source/nautobot_circuit_maintenance/views.py", line 14, in <module>
from nautobot_circuit_maintenance.handle_notifications.sources import RedirectAuthorize, Source
File "/source/nautobot_circuit_maintenance/handle_notifications/sources.py", line 185, in <module>
class EmailSource(Source): # pylint: disable=abstract-method
File "/usr/local/lib/python3.8/site-packages/pydantic/_internal/_model_construction.py", line 95, in __new__
private_attributes = inspect_namespace(
File "/usr/local/lib/python3.8/site-packages/pydantic/_internal/_model_construction.py", line 328, in inspect_namespace
raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `emails_to_fetch = []`. All model fields require a type annotation; if `emails_to_fetch` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.
For further information visit https://errors.pydantic.dev/2.0.1/u/model-field-missing-annotation
File "/source/nautobot_circuit_maintenance/views.py", line 14, in <module>
from nautobot_circuit_maintenance.handle_notifications.sources import RedirectAuthorize, Source
File "/source/nautobot_circuit_maintenance/handle_notifications/sources.py", line 415, in <module>
class GmailAPI(EmailSource):
File "/usr/local/lib/python3.8/site-packages/pydantic/_internal/_model_construction.py", line 95, in __new__
private_attributes = inspect_namespace(
File "/usr/local/lib/python3.8/site-packages/pydantic/_internal/_model_construction.py", line 328, in inspect_namespace
raise PydanticUserError(
pydantic.errors.PydanticUserError: A non-annotated attribute was detected: `SCOPES = ['https://www.googleapis.com/auth/gmail.readonly']`. All model fields require a type annotation; if `SCOPES` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.
For further information visit https://errors.pydantic.dev/2.0.1/u/model-field-missing-annotation
Steps to Reproduce
- Clone repo
- Run
invoke tests
The error does provide two solutions. However, I'm not sure the approach you guys want to take. Let me know and I can get a PR in!
I think at least part of the issue is that circuit-maintenance-parser
doesn't specify an upper bound on its pydantic
dependency. I haven't looked closely at pydantic 2.x but I'd be a bit surprised if it just worked out-of-the-box for us.
yes, maybe the simplest solution, for now, would be to pin the major version to 1.x and do a proper evaluation of changes to Pydantic 2.x
Sounds good. I will do that in the circuit-maintenance-parser
[here](Yeah, looks like it is in the circuit-maintenance-parser
here since that's where it looks like pydantic is coming from.
This is already solve, currently supported versions are pydantic = ">=1.10.4,<3"