Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

bsbodden
Copy link
Collaborator

Fix conflicting type expectations in IndexSchema constructor and validation.
The type annotation declared fields: Dict[str, BaseField] but the validator
raised an error when fields was actually provided as a dict.

Changes:

  • Update model validator to accept both list and dict formats for fields
  • Support dict with field definitions: {"field_name": {"name": "field_name", "type": "text"}}
  • Support dict with BaseField instances: {"field_name": BaseFieldInstance}
  • Maintain backward compatibility with existing list format

@bsbodden bsbodden requested a review from abrookins September 23, 2025 22:11
Copy link
Collaborator

@abrookins abrookins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some non-blocking comments and ideas for your consideration. 👍

  Fix conflicting type expectations in IndexSchema constructor and validation.
  The type annotation declared `fields: Dict[str, BaseField]` but the validator
  raised an error when fields was actually provided as a dict.

  Changes:
  - Update model validator to accept both list and dict formats for fields
  - Support dict with field definitions: {"field_name": {"name": "field_name", "type": "text"}}
  - Support dict with BaseField instances: {"field_name": BaseFieldInstance}
  - Maintain backward compatibility with existing list format
  - Use Field(default_factory=dict) instead of mutable default {}
  - Change fields type annotation from Dict to Mapping for better type safety
  - Use collections.abc.Mapping for isinstance checks
  - Use Sequence check with str/bytes exclusion for list detection
  - Add field name validation when BaseField is provided directly in dict format

Co-authored-by: Andrew Brookins <[email protected]>
@bsbodden bsbodden merged commit 42aa83b into main Sep 25, 2025
45 checks passed
@bsbodden bsbodden deleted the bsb/issue-361 branch September 25, 2025 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants