APIs¶
operators¶
This module contains the defined operators used to construct simple or more complex sql queries.
- sqlalchemy_filters.operators.register_operator(cls: Optional[Type] = None, *, sql_operator: Optional[Callable] = None)¶
Register a class as an operator class.
- Parameters
cls – Registering an operator without providing a builtin SQLAlchemy builtin operator.
sql_operator – A sqlalchemy operator or a custom callable that acts as an sqlalchemy operator.
- sqlalchemy_filters.operators.sa_1_4_compatible(f)¶
Decorator for the method
BaseOperator.to_sql
Since TextClause does not support BinaryExpression as a left operand in SqlAlchemy 1.4, we revert the left/right sides of the operation
Ex:
>>> # raises: unsupported operand type(s) for | TextClause and BinaryExpression >>> text("1 = 1") | (column("x") == 1)
would change to:
>>> (column("x") == 1) | text("1 = 1")
- class sqlalchemy_filters.operators.BaseOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
object
Base operator class.
Inherit from this class to create custom operators.
- operator: Callable¶
sqlalchemy operator, but can also be any callable that accepts
sql_expression
handled by sqlalchemy operators
- __init__(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
- sql_expression = None¶
Anything that can be used an operand for the sqlalchemy operators.
- params: list¶
A list of parameters or operands for the operator
- get_sql_expression() sqlalchemy.sql.elements.ClauseElement ¶
Returns a ClauseElement depends on the
sql_expression
is- Returns
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- classmethod check_params(params: list) None ¶
Validates the params.
Can be refined by subclasses to define a custom validation for
params
- Parameters
params – operands for the operator.
- Raises
InvalidParamError
if checking failed.
- __weakref__¶
list of weak references to the object (if defined)
- class sqlalchemy_filters.operators.IsOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
is sql operator.
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.IsNotOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.IsEmptyOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.IsNotEmptyOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.INOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.EqualsOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.RangeOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.LTEOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.LTOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.GTEOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.GTOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.AndOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.OrOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.ContainsOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.StartsWithOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.IStartsWithOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.StartsWithOperator
- to_sql()¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.EndsWithOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
- class sqlalchemy_filters.operators.IEndsWithOperator(sql_expression: sqlalchemy_filters.operators.V, params: Optional[List[sqlalchemy_filters.operators.T]] = None)¶
Bases:
sqlalchemy_filters.operators.BaseOperator
- to_sql() sqlalchemy.sql.elements.BinaryExpression ¶
Execute the operator against the database.
Filters¶
Modules defines the Filter and NestedFilter classes
- class sqlalchemy_filters.filters.NestedFilter(filter_class: Type[sqlalchemy_filters.filters.Filter], operator: Type[sqlalchemy_filters.operators.BaseOperator] = <class 'sqlalchemy_filters.operators.AndOperator'>, outer_operator: Optional[Type[sqlalchemy_filters.operators.BaseOperator]] = None, flat: bool = True, data_source_name: Optional[str] = None, marshmallow_schema=None)¶
Bases:
object
NestedFilters are a way to use already defined filter classes as fields and build complex queries.
- __init__(filter_class: Type[sqlalchemy_filters.filters.Filter], operator: Type[sqlalchemy_filters.operators.BaseOperator] = <class 'sqlalchemy_filters.operators.AndOperator'>, outer_operator: Optional[Type[sqlalchemy_filters.operators.BaseOperator]] = None, flat: bool = True, data_source_name: Optional[str] = None, marshmallow_schema=None)¶
- filter_class: Type[sqlalchemy_filters.filters.Filter]¶
The filter class that will be used as a
NestedFilter
field
- operator¶
- outer_operator: Optional[Type[sqlalchemy_filters.operators.BaseOperator]]¶
Operator describes how to join the inner fields of the NestedFilter and the field of the parent filter If not defined the operator of the parent filter will be used
- flat: bool = False¶
If True, means that the nested filter should get the value of its fields from root level of the data If False, the values will be extracted using either
data_source_name
if defined or the name of field in the parent filter:>>> # data for the nested filter will be extracted from the key `custom_field` >>> custom_field = NestedFilter(MyFilter, flat=False)
- data_source_name: Optional[str] = None¶
key to look for the nested filter fields from the data, this is ignored if
flat
is True.
- marshmallow_schema = None¶
Custom Marshmallow for validation
- __eq__(other)¶
Return self==value.
- get_data_source_name() str ¶
- Returns
key used to extract the data that will be used to validate and filter with.
- get_data(parent_filter_obj: sqlalchemy_filters.filters.BaseFilter) dict ¶
How to extract the data from the parent filter object.
- Parameters
parent_filter_obj – The parent filter object instance.
- Returns
data that will be passed to the
filter_class
- apply(parent_filter_obj: sqlalchemy_filters.filters.BaseFilter)¶
Gets the data from the parent filter then apply the filter for the
filter_class
- Parameters
parent_filter_obj – The parent filter object instance.
- Returns
the sql expression that will be combined with
parent_filter_obj
’s inner fields.
- __hash__ = None¶
- __weakref__¶
list of weak references to the object (if defined)
- class sqlalchemy_filters.filters.BaseFilter(*, data: dict, operator: Type[sqlalchemy_filters.operators.BaseOperator] = <class 'sqlalchemy_filters.operators.AndOperator'>, query=None, session=None, marshmallow_schema=None)¶
Bases:
object
Base filter that any other filter class should inherit from.
- fields: Dict[str, sqlalchemy_filters.fields.Field]¶
Fields declared using any class that inherits from
Filter
- nested: Dict[str, sqlalchemy_filters.filters.NestedFilter]¶
NestedFilter
- method_fields: Dict[str, sqlalchemy_filters.fields.MethodField]¶
Method fields
- validated: bool¶
Flag to whether the data was validated or not
- __init__(*, data: dict, operator: Type[sqlalchemy_filters.operators.BaseOperator] = <class 'sqlalchemy_filters.operators.AndOperator'>, query=None, session=None, marshmallow_schema=None)¶
- data: dict¶
Contains the original data passed to the constructor
- operator¶
Operator describing how to join the fields
alias of
Type
[sqlalchemy_filters.operators.BaseOperator
]
- session: Any = None¶
sqlalchemy session object
- marshmallow_schema: Any = None¶
marshmallow schema class
- set_query()¶
Sets the query to the current filter object (called at the
__init__()
method).- Returns
None
- validate_nested()¶
Validate all
NestedFilters
fields.- Raise
- Returns
None
- validate_fields()¶
Validates the data by calling
validate
of each field.Each validated value is put back inside
validated_data
using the return of field methodget_data_source_name
as a key. That value will be used as as input to the operator of the corresponding field.- Raise
- Returns
None
- validate()¶
Calls
validate_fields
andvalidate_nested
. If no error is raised, thevalidated
attribute is set to True- Returns
None
- __weakref__¶
list of weak references to the object (if defined)
- apply_fields()¶
Calls
apply_filter
of each field and join them using the definedoperator
- Returns
SQLAlchemy BinaryExpression
- apply_nested(filters)¶
Calls apply filter of each field and join them using the defined
operator
- Parameters
filters – The return value of
apply_fields()
- Returns
SQLAlchemy BinaryExpression
- apply_methods(filters)¶
Calls
apply_filter
of each field and join them- Parameters
filters – The return value of
apply_fields()
- Returns
SQLAlchemy BinaryExpression
- apply_all()¶
Validates the
data
and applies all the fields.This method can be used to get the sqlalchemy BinaryExpression without having to construct a SQLAlchemy Query object.
- Returns
SQLAlchemy BinaryExpression
- order_by(query)¶
Order the query by the specified order_by in the Meta class :param query: SQLAlchemy Query object. :return: Ordered SQLAlchemy Query object.
- paginate() sqlalchemy_filters.paginator.Paginator ¶
Creates a paginator that does all the work to slice the queries into a
Paginator
object.- Returns
Return a
Paginator
- apply()¶
Applies all fields, then using that result to filter the query then apply the joining of any potentiel foreign keys.
- Returns
SQLAlchemy Query object.
- class sqlalchemy_filters.filters.Filter(*, marshmallow_schema: Optional[Type] = None, **kwargs)¶
Bases:
sqlalchemy_filters.mixins.MarshmallowValidatorFilterMixin
,sqlalchemy_filters.filters.BaseFilter
Filter class.
Makes use of MarshmallowValidatorFilterMixin to add the marshmallow validation capability.
Fields¶
This module defines all types of fields used by the filter classes.
- class sqlalchemy_filters.fields.BaseField(*, field_name: Optional[str] = None, lookup_operator: Optional[Type[sqlalchemy_filters.operators.BaseOperator]] = <class 'sqlalchemy_filters.operators.EqualsOperator'>, join: Optional[Union[Any, Tuple[Any, Any]]] = None, custom_column: Optional[sqlalchemy.sql.elements.ColumnClause] = None, data_source_name: Optional[str] = None, allow_none: Optional[bool] = False)¶
Bases:
object
Base field class
- __init__(*, field_name: Optional[str] = None, lookup_operator: Optional[Type[sqlalchemy_filters.operators.BaseOperator]] = <class 'sqlalchemy_filters.operators.EqualsOperator'>, join: Optional[Union[Any, Tuple[Any, Any]]] = None, custom_column: Optional[sqlalchemy.sql.elements.ColumnClause] = None, data_source_name: Optional[str] = None, allow_none: Optional[bool] = False) None ¶
- Parameters
field_name –
- Field name of the model, can also refer to a field in a foreign key.
We don’t not have to specify it if that field name that’s defined with is the same as the model attribute
>>> class MyFilter(Filter): >>> # field1 is not a attribute/field of the model >>> # hence we specified it explicitly >>> field1 = Field(field_name="column") >>> # field2 is an attribute/field of the model >>> # we don't have to explicitly declare it >>> field2 = Field() >>> field3 = Field(field_name="foreign_model.attribute") >>> ...
lookup_operator – The operator class used to join the fields filtering together. Can only be AndOperator or OrOperator.
join – A Model to join the query with, can also be a tuple. This will be passed to the join method of the SQLAlchemy Query object.
custom_column –
- You can use a custom column to filter with. It can accept a string, a column or a Model
field
>>> from sqlalchemy import column >>> >>> class MyFilter(Filter): >>> field1 = Field(custom_column="my_column") >>> field2 = Field(custom_column=column("some_column")) >>> field3 = Field(custom_column=MyModel.field) >>> ...
data_source_name – The key used to extract the value of the field from the data provided.
allow_none – (default to
False
): If set to True it allows filtering with None values. But Only if the data contains the value None
- __eq__(other)¶
Return self==value.
- validate(value) Any ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
- get_data_source_name() str ¶
- Returns
Return the key to be used to look for the value of the field.
- get_field_value(data)¶
- Parameters
data – Data provided while instantiating the filter class (pre-validation:
data
)- Returns
The field value from the data, if not found it returns Empty class.
- get_field_value_for_filter(filter_obj)¶
Extracts the value of the field from the
validated_data
.- Parameters
filter_obj – The filter instance
- Returns
The field value from the data, if not found it returns Empty class.
- apply_filter(filter_obj)¶
- Applies the filtering part using the operator class and the value extracted using
- Parameters
filter_obj – The Filter instance
- Returns
SQLAlchemy BinaryExpression
- __hash__ = None¶
- __weakref__¶
list of weak references to the object (if defined)
- class sqlalchemy_filters.fields.MethodField(*, method: Union[Callable, str], data_source_name=None)¶
Bases:
sqlalchemy_filters.fields.BaseField
Field used to delegate the filtering logic to a Filter method or a standalone function.
- Warning
The
MethodField
does not provide any validation and consumes any values extracted from thedata
field.
- __init__(*, method: Union[Callable, str], data_source_name=None)¶
- Parameters
method – A callable that accepts a single value which is the field value.
data_source_name – The key used to extract the value of the field from the data provided.
- method: Callable¶
- class sqlalchemy_filters.fields.Field(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.mixins.ForeignKeyFieldMixin
,sqlalchemy_filters.fields.BaseField
This is the Default field instance that can be instantiated as used as a filter field.
- class sqlalchemy_filters.fields.TypedField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.Field
- validate(value: Any) Any ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
- class sqlalchemy_filters.fields.IntegerField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TypedField
- type_¶
alias of
int
- class sqlalchemy_filters.fields.DecimalField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TypedField
- type_¶
alias of
decimal.Decimal
- class sqlalchemy_filters.fields.FloatField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TypedField
- type_¶
alias of
float
- class sqlalchemy_filters.fields.StringField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TypedField
- type_¶
alias of
str
- class sqlalchemy_filters.fields.BooleanField(*, field_name=None, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TypedField
- type_¶
alias of
bool
- class sqlalchemy_filters.fields.TimestampField(*, timezone=datetime.timezone.utc, **kwargs)¶
Bases:
sqlalchemy_filters.fields.FloatField
- __init__(*, timezone=datetime.timezone.utc, **kwargs)¶
- Parameters
field_name –
- Field name of the model, can also refer to a field in a foreign key.
We don’t not have to specify it if that field name that’s defined with is the same as the model attribute
>>> class MyFilter(Filter): >>> # field1 is not a attribute/field of the model >>> # hence we specified it explicitly >>> field1 = Field(field_name="column") >>> # field2 is an attribute/field of the model >>> # we don't have to explicitly declare it >>> field2 = Field() >>> field3 = Field(field_name="foreign_model.attribute") >>> ...
lookup_operator – The operator class used to join the fields filtering together. Can only be AndOperator or OrOperator.
join – A Model to join the query with, can also be a tuple. This will be passed to the join method of the SQLAlchemy Query object.
custom_column –
- You can use a custom column to filter with. It can accept a string, a column or a Model
field
>>> from sqlalchemy import column >>> >>> class MyFilter(Filter): >>> field1 = Field(custom_column="my_column") >>> field2 = Field(custom_column=column("some_column")) >>> field3 = Field(custom_column=MyModel.field) >>> ...
data_source_name – The key used to extract the value of the field from the data provided.
allow_none – (default to
False
): If set to True it allows filtering with None values. But Only if the data contains the value None
- validate(value: Union[int, float]) datetime.datetime ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
- class sqlalchemy_filters.fields.BaseDateField(*, date_format: str = '%Y-%m-%d', is_timestamp=False, **kwargs)¶
Bases:
sqlalchemy_filters.fields.TimestampField
- __init__(*, date_format: str = '%Y-%m-%d', is_timestamp=False, **kwargs)¶
- Parameters
date_format – date_format that can be accepted by the datetime.strptime method.
is_timestamp – True if it’s intented to be used as a timestamp
kwargs –
- validate(value: Union[str, datetime.datetime, datetime.date, int, float]) datetime.datetime ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
- class sqlalchemy_filters.fields.DateTimeField(*, datetime_format: str = '%Y-%m-%d', **kwargs)¶
Bases:
sqlalchemy_filters.fields.BaseDateField
- __init__(*, datetime_format: str = '%Y-%m-%d', **kwargs)¶
- Parameters
date_format – date_format that can be accepted by the datetime.strptime method.
is_timestamp – True if it’s intented to be used as a timestamp
kwargs –
- validate(value: Union[str, datetime.datetime, datetime.date, int, float]) datetime.datetime ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
- class sqlalchemy_filters.fields.DateField(*, date_format: str = '%Y-%m-%d', is_timestamp=False, **kwargs)¶
Bases:
sqlalchemy_filters.fields.BaseDateField
- validate(value: Union[float, int, str, datetime.datetime, datetime.date]) datetime.date ¶
Validates the value
- Parameters
value – value extracted from the original data
- Returns
Sanitized or original value
- Raises
FieldValidationError
if validation fails. This is used for custom validation.
Paginator¶
- class sqlalchemy_filters.paginator.Paginator(query, page: int, page_size: int)¶
Bases:
object
Utility class to help paginate through results of a SQLAlchemy query.
This is a 1-based index, meaning page=1 is the first page.
- __init__(query, page: int, page_size: int)¶
- has_next_page()¶
- Returns
True if the current has is not the last page .
- has_previous_page()¶
- Returns
True if the current has is not the first page .
- next_page()¶
If this current paginator is the last page, then this method will return the current one.
- Returns
Paginator object
- previous_page()¶
If this current paginator is the first page, then this method will return the current one.
- Returns
Paginator object
- get_objects()¶
- Returns
Evaluates the query and returns the objects from the database.
- get_sliced_query()¶
- Returns
Can be used to get the sliced version of the query without evaluating it
- to_json()¶
- Returns
dictionary containing useful data in case of paginating through an API.
Example:
>>> paginator.to_json() { "count": 111, "page_size": 10, "page": 2, "num_pages": 12, "has_next_page": True, "has_prev_page": True, }
- __weakref__¶
list of weak references to the object (if defined)
Exceptions¶
This module defined all exceptions used by the library.
- exception sqlalchemy_filters.exceptions.BaseError¶
Bases:
Exception
Base Exception for all exceptions.
- exception sqlalchemy_filters.exceptions.InvalidParamError(message: str)¶
Bases:
sqlalchemy_filters.exceptions.BaseError
Raised during the call of the
check_params
method of the Operator class.
- exception sqlalchemy_filters.exceptions.FieldMethodNotFound(parent_filter: Type, field_name: str, method_name: str)¶
Bases:
sqlalchemy_filters.exceptions.BaseError
Raised when a method specified using string is not found in the filter class.
- exception sqlalchemy_filters.exceptions.FieldValidationError(message: Optional[str] = None)¶
Bases:
sqlalchemy_filters.exceptions.BaseError
- default_error: str = 'error validating this field.'¶
default error message
- set_field_name(field_name: str) None ¶
sets
field_name
- Parameters
field_name – The field name of the errored field name.
- Returns
None
- json() Dict[Optional[str], str] ¶
Converts the error into a dictionary {field_name: error_message} :return: dict
- exception sqlalchemy_filters.exceptions.FilterValidationError(field_errors: List[sqlalchemy_filters.exceptions.FieldValidationError])¶
Bases:
sqlalchemy_filters.exceptions.BaseError
- field_errors: List[sqlalchemy_filters.exceptions.FieldValidationError]¶
List of
FieldValidationError
- json() List[Dict[Optional[str], str]] ¶
Jsonify all the
sqlalchemy_filters.exceptions.FieldValidationError
exceptions- Returns
List of dictionary representing the errors for each field
Example:
>>> exc.json() [ {"age": "Expected to be of type int"}, {"last_name": "Expected to be of type str"} ]
- exception sqlalchemy_filters.exceptions.OrderByException¶
Bases:
sqlalchemy_filters.exceptions.BaseError
Raised when trying to order by a field that does not belong to the filter’s model.