remove date dumping to isoformat, add pydantic 1.9 support
This commit is contained in:
@ -20,7 +20,6 @@ except ImportError: # pragma: no cover
|
||||
import pydantic
|
||||
from pydantic.class_validators import make_generic_validator
|
||||
from pydantic.fields import ModelField, SHAPE_LIST
|
||||
from pydantic.main import SchemaExtraCallable
|
||||
|
||||
import ormar # noqa: I100, I202
|
||||
from ormar.models.helpers.models import meta_field_not_set
|
||||
@ -249,7 +248,7 @@ def overwrite_binary_format(schema: Dict[str, Any], model: Type["Model"]) -> Non
|
||||
]
|
||||
|
||||
|
||||
def construct_modify_schema_function(fields_with_choices: List) -> SchemaExtraCallable:
|
||||
def construct_modify_schema_function(fields_with_choices: List) -> Callable:
|
||||
"""
|
||||
Modifies the schema to include fields with choices validator.
|
||||
Those fields will be displayed in schema as Enum types with available choices
|
||||
@ -275,7 +274,7 @@ def construct_modify_schema_function(fields_with_choices: List) -> SchemaExtraCa
|
||||
return staticmethod(schema_extra) # type: ignore
|
||||
|
||||
|
||||
def construct_schema_function_without_choices() -> SchemaExtraCallable:
|
||||
def construct_schema_function_without_choices() -> Callable:
|
||||
"""
|
||||
Modifies model example and description if needed.
|
||||
|
||||
|
||||
@ -76,7 +76,6 @@ class NewBaseModel(pydantic.BaseModel, ModelTableProxy, metaclass=ModelMetaclass
|
||||
pk: Any
|
||||
__model_fields__: Dict[str, BaseField]
|
||||
__table__: sqlalchemy.Table
|
||||
__fields__: Dict[str, pydantic.fields.ModelField]
|
||||
__pydantic_model__: Type[BaseModel]
|
||||
__pkname__: str
|
||||
__tablename__: str
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import datetime
|
||||
from typing import Any, Dict, TYPE_CHECKING, Type
|
||||
|
||||
import sqlalchemy
|
||||
@ -138,8 +137,6 @@ class FilterAction(QueryAction):
|
||||
if isinstance(self.filter_value, ormar.Model):
|
||||
self.filter_value = self.filter_value.pk
|
||||
|
||||
self._convert_dates_if_required()
|
||||
|
||||
op_attr = FILTER_OPERATORS[self.operator]
|
||||
if self.operator == "isnull":
|
||||
op_attr = "is_" if self.filter_value else "isnot"
|
||||
@ -152,23 +149,6 @@ class FilterAction(QueryAction):
|
||||
)
|
||||
return clause
|
||||
|
||||
def _convert_dates_if_required(self) -> None:
|
||||
"""
|
||||
Converts dates, time and datetime to isoformat
|
||||
"""
|
||||
if isinstance(
|
||||
self.filter_value, (datetime.date, datetime.time, datetime.datetime)
|
||||
):
|
||||
self.filter_value = self.filter_value.isoformat()
|
||||
|
||||
if isinstance(self.filter_value, (list, tuple, set)):
|
||||
self.filter_value = [
|
||||
x.isoformat()
|
||||
if isinstance(x, (datetime.date, datetime.time, datetime.datetime))
|
||||
else x
|
||||
for x in self.filter_value
|
||||
]
|
||||
|
||||
def _compile_clause(
|
||||
self, clause: sqlalchemy.sql.expression.BinaryExpression, modifiers: Dict
|
||||
) -> sqlalchemy.sql.expression.TextClause:
|
||||
|
||||
Reference in New Issue
Block a user