CaptureQueriesContext
Context manager that captures queries executed by the specified connection.
Attributes
| Attribute | Type | Description |
|---|---|---|
| connection | [BaseDatabaseWrapper](../../db/backends/base/base/basedatabasewrapper.md?sid=django_db_backends_base_base_basedatabasewrapper) | The database connection object whose executed queries are being monitored and captured. |
| force_debug_cursor | boolean | Stores the original state of the connection's debug cursor setting to ensure it is restored after the context manager exits. |
| initial_queries | integer | The count of queries logged by the connection at the start of the context, used as the lower bound for slicing captured queries. |
| final_queries | integer = null | The count of queries logged by the connection at the end of the context, used as the upper bound for slicing captured queries. |
| reset_queries_disconnected | boolean | A boolean indicating whether the query reset signal was successfully disconnected to prevent query log clearing during capture. |
| captured_queries | list | A property that returns a list of queries executed specifically within the scope of the context manager. |
Constructor
Signature
def CaptureQueriesContext(
connection: [BaseDatabaseWrapper](../../db/backends/base/base/basedatabasewrapper.md?sid=django_db_backends_base_base_basedatabasewrapper)
)
Parameters
| Name | Type | Description |
|---|---|---|
| connection | [BaseDatabaseWrapper](../../db/backends/base/base/basedatabasewrapper.md?sid=django_db_backends_base_base_basedatabasewrapper) | The database connection object whose queries will be captured. |
Methods
captured_queries()
@classmethod
def captured_queries() - > list
Calculates and returns the subset of queries from the connection log that occurred during this context.
Returns
| Type | Description |
|---|---|
list | A list of dictionaries representing the SQL queries executed between the enter and exit points |