openedx / platform-plugin-aspects

Aspects plugins for the Open edX LMS and Studio
Apache License 2.0
2 stars 8 forks source link

Graceful Error Handling for Missing Models in EVENT_SINK_CLICKHOUSE_MODEL_CONFIG to Prevent Platform Disruptions #96

Open anfbermudezme opened 3 days ago

anfbermudezme commented 3 days ago

Issue Type: Enhancement

Summary

Improve error handling when retrieving models within the get_model method and signals to prevent disruptions in platform processes such as course enrollments when the model is not present in the EVENT_SINK_CLICKHOUSE_MODEL_CONFIG setting.

Description

Currently, when making a request using the get_model method and the specified model does not exist, an exception is raised, logging the error here: Link to Code.

However, within the signal handling process, the method *Model*.objects.get is used to retrieve models. If the model is missing from the EVENT_SINK_CLICKHOUSE_MODEL_CONFIG setting, it throws a AttributeError: 'NoneType' object has no attribute 'objects'” exception, as the process does not terminate gracefully. This forces the model to be explicitly included in the configuration, leading to interruptions in critical platform processes like course enrollments (Link to Signals).

Suggested Enhancement

The current behavior mandates that models must exist in the configuration. Failure to do so results in unhandled exceptions that break the natural flow of platform operations. To enhance robustness:

  1. Graceful Fallback: Implement a more graceful fallback mechanism in the case where the model is not found. Instead of raising a hard exception, log the error and allow the process to continue where possible.
  2. Soft Error Handling: Adjust the plugin's behavior to report such errors without crashing core functionalities of the platform, allowing the default platform behavior to continue unaffected.

This improvement will ensure that platform processes like enrollments do not get disrupted, even if the plugin configuration is incomplete.

Steps to Reproduce

  1. Remove CourseEnrollment from the EVENT_SINK_CLICKHOUSE_MODEL_CONFIG setting.
  2. Attempt to enroll a user through any part of the platform.
  3. Observe the thrown exception and the resulting error message.

Expected Behavior

Actual Behavior

Proposed Fix

Environment