django_assert_queries.query_catcher¶
Utilities for capturing and inspecting database queries.
New in version 1.0.
Functions
|
Catch queries and provide information for further inspection. |
Classes
|
Context for captured query information. |
Information on an executed query. |
|
|
A type of executed query that can be inspected. |
Information on a subquery within an executed query. |
- class django_assert_queries.query_catcher.ExecutedQueryType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]¶
-
A type of executed query that can be inspected.
New in version 1.0.
- __format__(format_spec)¶
Return a formatted version of the string as described by format_spec.
- __new__(value)¶
- __repr__()¶
Return repr(self).
- __str__()¶
Return str(self).
- class django_assert_queries.query_catcher.ExecutedQueryInfo[source]¶
Bases:
TypedDictInformation on an executed query.
This contains information seen at execution time that can be used for inspection of the queries.
This should not be populated by consumers, only by this library.
New in version 1.0.
- query: Query¶
The query that was executed.
- result_type: Literal['query']¶
The type of result information.
This is used to distinguish between query and subquery information.
- subqueries: List[ExecutedSubQueryInfo]¶
Any subqueries within this query, in the orders found.
- type: ExecutedQueryType¶
The type of executed query.
- class django_assert_queries.query_catcher.ExecutedSubQueryInfo[source]¶
Bases:
TypedDictInformation on a subquery within an executed query.
This contains information seen at execution time that can be used for inspection of the queries.
This should not be populated by consumers, only by this library.
New in version 1.0.
- instance: AggregateQuery | QuerySet | Subquery¶
The instance of the subquery class.
- query: Query¶
The query that was executed.
- result_type: Literal['subquery']¶
The type of result information.
This is used to distinguish between query and subquery information.
- subqueries: List[ExecutedSubQueryInfo]¶
Any subqueries within this query, in the orders found.
- class django_assert_queries.query_catcher.CatchQueriesContext(deleted_objects: Mapping[int, Any], executed_queries: Sequence[ExecutedQueryInfo], queries_to_qs: Dict[Query, Q])[source]¶
Bases:
objectContext for captured query information.
This is provided and populated when using
catch_queries().This should not be populated by consumers, only by this library.
New in version 1.0.
- deleted_objects: Mapping[int, Any]¶
A mapping of deleted instance IDs to their original primary keys.
New in version 2.0.
- executed_queries: Sequence[ExecutedQueryInfo]¶
Information on the queries that were executed.
- __eq__(other)¶
Return self==value.
- __hash__ = None¶
- __init__(deleted_objects: Mapping[int, Any], executed_queries: Sequence[ExecutedQueryInfo], queries_to_qs: Dict[Query, Q]) None¶
- __repr__()¶
Return repr(self).
- django_assert_queries.query_catcher.catch_queries(*, _check_subqueries: bool = True) Iterator[CatchQueriesContext][source]¶
Catch queries and provide information for further inspection.
Any database queries executed during this context will be captured and provided in the context. For each query, this will capture:
The type of query.
The
SQL Query objectsThe generated SQL statements
Tracebacks showing where the SQL was executed.
It will also provide a mapping of the Query objects to their Q expressions.
New in version 1.0.
- Parameters:
_check_subqueries (
bool, optional) –Whether to check subqueries.
This is internal for compatibility with the old behavior for
assert_queries>()and will be removed in a future release without a deprecation period.- Context:
CatchQueriesContext– The context populated with query information.