| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Fixed a bug where using Dict or Mapping type hints with Relationship() would cause infinite recursion. The get_relationship_to() function now properly handles dict/Mapping types by extracting the value type (second type argument), similar to how it handles List types. Changes: - Added handling for dict and Mapping origins in get_relationship_to() - Extracts the value type from Dict[K, V] or Mapping[K, V] annotations - Added comprehensive tests for Dict relationships with attribute_mapped_collection This resolves the RecursionError that occurred when defining relationships like: children: Dict[str, Child] = Relationship(...) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
…cursion-011CUbiwV1LogX5vM5VcjpbW Fix RecursionError with Dict relationships in get_relationship_to()
|
We already have #1287 that fixes this issue. |
Sorry, something went wrong.
| class Parent(SQLModel, table=True): | ||
| __tablename__ = "parent" | ||
| id: int = Field(primary_key=True) | ||
| children: Optional[Dict[str, "Child"]] = Relationship( |
There was a problem hiding this comment.
Does it make sense to use Optional here?
Sorry, something went wrong.
There was a problem hiding this comment.
I think you can make a reasonable argument either way. After going back and forth with Claude some, I decided that it made sense because it lets you distinguish between not loaded and empty, but I dont have exceptionally strong feelings and can change it.
Sorry, something went wrong.
When using Annotated[type, Field(sa_column=...), Validator(...)], Pydantic V2 creates a new pydantic.fields.FieldInfo that doesn't preserve SQLModel-specific attributes like sa_column and sa_type. This caused timezone-aware datetime columns defined with DateTime(timezone=True) to lose their timezone setting. The fix extracts the SQLModel FieldInfo from the original Annotated type's metadata, preserving sa_column and sa_type attributes even when Pydantic V2 merges the field info. Fixes timezone-aware datetime columns losing timezone=True when using Annotated types with Pydantic validators.
…-01QW9NWe9vXN7RPhTDLfCs6m Fix sa_column/sa_type lost when using Annotated with validators
| Back | FazBrowse Home | New Git URL |
Relates to: #835
Quick little fix for a recursion bug when annotating a member as a Dictionary or Mapping.