feat: Add Pydantic BaseModel and dataclass support for Python type inference #7329
+488
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds Pydantic BaseModel and Python dataclass support to the Python parser, enabling automatic UI generation for complex data structures.
Closes #4700
Changes
Modified
backend/parsers/windmill-parser-py/src/lib.rsto detect Pydantic models and dataclasses via AST analysis. The parser now recognizes these custom types and extracts their field schemas without executing any Python code.Implementation
The parser uses rustpython AST to pattern match class inheritance and decorators, then recursively extracts field types. Added thread-safe module storage with RAII cleanup and security limits (200 fields max, 10 recursion levels).
Example
Before:
After:
Windmill now automatically generates a form with name, age, and email fields from the User model.
Testing
Added 3 test cases covering basic models, dataclasses, and nested models. All 12 tests pass. No breaking changes to existing functionality.
Known Limitations
Field default values and validation metadata are not yet extracted. Forward references and union types are not supported. These can be addressed in follow-up PRs if needed.