(
cls,
name: str,
bases: tuple[type[Any], ...],
class_dict: dict[str, Any],
**kwargs: Any,
)
| 538 | |
| 539 | # From Pydantic |
| 540 | def __new__( |
| 541 | cls, |
| 542 | name: str, |
| 543 | bases: tuple[type[Any], ...], |
| 544 | class_dict: dict[str, Any], |
| 545 | **kwargs: Any, |
| 546 | ) -> Any: |
| 547 | relationships: dict[str, RelationshipInfo] = {} |
| 548 | dict_for_pydantic = {} |
| 549 | original_annotations = get_annotations(class_dict) |
| 550 | pydantic_annotations = {} |
| 551 | relationship_annotations = {} |
| 552 | for k, v in class_dict.items(): |
| 553 | if isinstance(v, RelationshipInfo): |
| 554 | relationships[k] = v |
| 555 | else: |
| 556 | dict_for_pydantic[k] = v |
| 557 | for k, v in original_annotations.items(): |
| 558 | if k in relationships: |
| 559 | relationship_annotations[k] = v |
| 560 | else: |
| 561 | pydantic_annotations[k] = v |
| 562 | dict_used = { |
| 563 | **dict_for_pydantic, |
| 564 | "__weakref__": None, |
| 565 | "__sqlmodel_relationships__": relationships, |
| 566 | "__annotations__": pydantic_annotations, |
| 567 | } |
| 568 | # Duplicate logic from Pydantic to filter config kwargs because if they are |
| 569 | # passed directly including the registry Pydantic will pass them over to the |
| 570 | # superclass causing an error |
| 571 | allowed_config_kwargs: set[str] = { |
| 572 | key |
| 573 | for key in dir(BaseConfig) |
| 574 | if not ( |
| 575 | key.startswith("__") and key.endswith("__") |
| 576 | ) # skip dunder methods and attributes |
| 577 | } |
| 578 | config_kwargs = { |
| 579 | key: kwargs[key] for key in kwargs.keys() & allowed_config_kwargs |
| 580 | } |
| 581 | new_cls = cast( |
| 582 | "SQLModel", super().__new__(cls, name, bases, dict_used, **config_kwargs) |
| 583 | ) |
| 584 | new_cls.__annotations__ = { |
| 585 | **relationship_annotations, |
| 586 | **pydantic_annotations, |
| 587 | **new_cls.__annotations__, |
| 588 | } |
| 589 | |
| 590 | def get_config(name: str) -> Any: |
| 591 | config_class_value = new_cls.model_config.get(name, Undefined) |
| 592 | if config_class_value is not Undefined: |
| 593 | return config_class_value |
| 594 | kwarg_value = kwargs.get(name, Undefined) |
| 595 | if kwarg_value is not Undefined: |
| 596 | return kwarg_value |
| 597 | return Undefined |
nothing calls this directly
no test coverage detected