|
26 | 26 | ) |
27 | 27 |
|
28 | 28 | from pydantic import ( |
29 | | - AwareDatetime, |
30 | 29 | BaseModel, |
31 | 30 | EmailStr, |
32 | | - FutureDate, |
33 | | - FutureDatetime, |
34 | | - NaiveDatetime, |
35 | | - PastDate, |
36 | | - PastDatetime, |
37 | 31 | ) |
38 | 32 | from pydantic.fields import FieldInfo as PydanticFieldInfo |
39 | 33 | from sqlalchemy import ( |
|
91 | 85 | ) |
92 | 86 | from .sql.sqltypes import AutoString |
93 | 87 |
|
| 88 | +if IS_PYDANTIC_V2: |
| 89 | + from pydantic import ( |
| 90 | + AwareDatetime, |
| 91 | + FutureDate, |
| 92 | + FutureDatetime, |
| 93 | + NaiveDatetime, |
| 94 | + PastDate, |
| 95 | + PastDatetime, |
| 96 | + ) |
| 97 | + |
94 | 98 | if TYPE_CHECKING: |
95 | 99 | from pydantic._internal._model_construction import ModelMetaclass as ModelMetaclass |
96 | 100 | from pydantic._internal._repr import Representation as Representation |
@@ -689,18 +693,23 @@ def get_sqlalchemy_type(field: Any) -> Any: |
689 | 693 | return Boolean |
690 | 694 | if issubclass(type_, int): |
691 | 695 | return Integer |
692 | | - if issubclass(type_, (datetime, FutureDatetime, PastDatetime)): |
| 696 | + if issubclass(type_, datetime): |
693 | 697 | return DateTime |
694 | | - if issubclass(type_, (date, FutureDate, PastDate)): |
| 698 | + if issubclass(type_, date): |
695 | 699 | return Date |
696 | 700 | if issubclass(type_, timedelta): |
697 | 701 | return Interval |
698 | 702 | if issubclass(type_, time): |
699 | 703 | return Time |
700 | | - if issubclass(type_, AwareDatetime): |
701 | | - return DateTime(timezone=True) |
702 | | - if issubclass(type_, NaiveDatetime): |
703 | | - return DateTime(timezone=False) |
| 704 | + if IS_PYDANTIC_V2: |
| 705 | + if issubclass(type_, (FutureDate, PastDate)): |
| 706 | + return DateTime |
| 707 | + if issubclass(type_, (FutureDatetime, PastDatetime)): |
| 708 | + return DateTime |
| 709 | + if issubclass(type_, AwareDatetime): |
| 710 | + return DateTime(timezone=True) |
| 711 | + if issubclass(type_, NaiveDatetime): |
| 712 | + return DateTime(timezone=False) |
704 | 713 | if issubclass(type_, bytes): |
705 | 714 | return LargeBinary |
706 | 715 | if issubclass(type_, Decimal): |
|
0 commit comments