Help with griffe-pydantic: Validators and Config not grouping as expected
#54
-
|
Hello! 👋 I'm currently trying to integrate The Goal: The Current Result: Versions: My Configuration ( - mkdocstrings:
default_handler: python
handlers:
python:
paths: ["app"]
inventories:
- https://docs.python.org/3/objects.inv
- https://docs.pydantic.dev/latest/objects.inv
options:
show_source: false
show_root_full_path: false
show_root_heading: true
# show_signature: false
show_signature_annotations: true
modernize_annotations: true
show_labels: true
show_symbol_type_heading: true
show_symbol_type_toc: true
show_if_no_docstring: true
show_category_heading: true
group_by_category: true
members_order: source
docstring_style: numpy
extensions:
- griffe_pydantic:
schema: trueMinimal Example from pydantic import BaseModel, ConfigDict, field_validator
class ExampleModel(BaseModel):
"""Example Model"""
model_config = ConfigDict(frozen=False)
field_without_validator: str
"""Field 1"""
field_with_validator: int
"""Field 2"""
@field_validator("field_with_validator")
@classmethod
def age_must_be_positive(cls, v: int):
"""Validate positive integer"""
if v <= 0:
raise ValueError("Must be positive")
return vI suspect I might be missing some setttings or perhaps a specific version of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
I cannot reproduce the issue you describe 😕 And I don't see anything wrong in this setup. Feel free to open a bug report with a minimal reproduction example packed in a zip file 🙂 |
Beta Was this translation helpful? Give feedback.


Hi @pawamoy,
Thanks for taking the time to look into this! After further investigation, I finally tracked down the cause. It wasn't a configuration error, but rather a side effect of how the extension handles modules that fail to import.
The Issue:
If a module contains a runtime error (like an undefined variable) or (in my previous case) a Pydantic BaseSettings class fails to instantiate (e.g., due to missing environment variables), the module fails to be fully imported/resolved.
In these cases, griffe still successfully performs static analysis and renders the class as a standard Python object, but the griffe-pydantic extension doesn't "kick in." This results in the standard attributes l…