Receivers

Django signal receivers for connection app.

smarter.apps.connection.receivers.handle_api_connection_attempted(sender, connection, **kwargs)[source]

Log an API connection attempt.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_failed(sender, connection, error=None, **kwargs)[source]

Log, at INFO level, that an API connection failed and is not ready.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • error (str | None) – Why it failed, if known. It is not logged.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_pre_delete(sender, instance, **kwargs)[source]

Log that an ApiConnection is about to be deleted.

Parameters:
  • sender – The class that sent the signal.

  • instance – The ApiConnection being deleted.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_query_attempted(sender, connection, **kwargs)[source]

Log an API query attempt.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_query_failed(sender, connection, status_code=None, error=None, **kwargs)[source]

Log, at INFO level, a failed API query, with its response’s status, if any, and why it failed.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • status_code (int | None) – The response’s HTTP status, or None when there was no response.

  • error (str | None) – Why the query failed.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_query_success(sender, connection, status_code=None, **kwargs)[source]

Log a successful API query, with its response’s status.

The response isn’t logged: an api’s response can hold personal data, and Smarter’s log is shown to users in DEBUG mode.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • status_code (int | None) – The response’s HTTP status.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_saved(sender, instance, created, **kwargs)[source]

Log that an ApiConnection was created or updated, and its whole row at DEBUG level.

Parameters:
  • sender – The class that sent the signal.

  • instance – The ApiConnection that was saved.

  • created – True if the row was created, False if it was updated.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_api_connection_success(sender, connection, **kwargs)[source]

Log that an API connection succeeded and is ready.

Parameters:
  • sender – The class that sent the signal.

  • connection (ApiConnection) – The ApiConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_attempted(sender, connection, **kwargs)[source]

Log a SQL connection attempt, with the masked connection string.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_failed(sender, connection, error, **kwargs)[source]

Handle SQL connection failed signal.

Only logs the failure: the method that sent the signal reports it to its caller, by returning None. The connection string is always masked, so that its password is never logged.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection that failed.

  • error (str) – Why it failed.

  • kwargs – Other signal arguments: stage, what failed, e.g. "SSH connection".

smarter.apps.connection.receivers.handle_sql_connection_pre_delete(sender, instance, **kwargs)[source]

Log that a SqlConnection is about to be deleted.

Parameters:
  • sender – The class that sent the signal.

  • instance – The SqlConnection being deleted.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_query_attempted(sender, connection, sql, limit, **kwargs)[source]

Log a SQL query attempt, with its SQL and row limit.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection.

  • sql (str) – The SQL query.

  • limit (int) – The row limit of the query.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_query_failed(sender, connection, sql, limit, error, **kwargs)[source]

Handle SQL connection query failed signal.

Only logs the failure: execute_query(), which sent the signal, reports it to its caller by returning False.

smarter.apps.connection.receivers.handle_sql_connection_query_success(sender, connection, sql, limit, **kwargs)[source]

Log a successful SQL query, with its SQL and row limit.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection.

  • sql (str) – The SQL query.

  • limit (int) – The row limit of the query.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_saved(sender, instance, created, **kwargs)[source]

Log that a SqlConnection was created or updated, and its whole row at DEBUG level.

Parameters:
  • sender – The class that sent the signal.

  • instance (SqlConnection) – The SqlConnection that was saved.

  • created – True if the row was created, False if it was updated.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_success(sender, connection, **kwargs)[source]

Log that a SQL connection succeeded and is ready.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.handle_sql_connection_validated(sender, connection, **kwargs)[source]

Log that a SQL connection was validated.

Parameters:
  • sender – The class that sent the signal.

  • connection (SqlConnection) – The SqlConnection.

  • kwargs – Other keyword arguments sent with the signal.

smarter.apps.connection.receivers.masked_dict(dic)[source]

Mask sensitive data in a dictionary.

Return type:

dict[str, Any]