Open robrap opened 1 week ago
@robrap I have not written a plugin with openedx-events, but I agree that if we have two equally-powerful ways of implementing receivers, one which uses idiomatic Python/Django and the other of which has a bespoke stringly-typed config syntax, then we should keep the former and depr the latter.
Inside edx-platform, there are many uses of apps.py to listen to signals. See https://github.com/search?q=repo%3Aopenedx%2Fedx-platform+plugin_app&type=code. I find this very confusing, because it is using "plugin" syntax for non-plugin apps that live inside the repo. Is there any good reason to do this, or is this just a lot of copy/paste of something that doesn't make as much sense?
Yes, I find that confusing too. This all predate ADRs, but I believe that the reasoning at the time was something like:
Built-in XBlocks are still XBlocks, so built-in Django apps should still be plugins.
I could write more about why I disagree with each of those, but to be brief, I think that building internal apps as django plugins has just led to a stranger, more-indirect codebase with a higher barrier to entry for new maintainers.
If we turn built-in edx-platform djangoapps into plugins, then it'll make them easier to extract.
I believe that the second option, using apps.py plugin configuration, pre-dates the use of openedx-events. In the earliest version of plugins, they needed to reach into a signal definition that was defined in edx-platform (as an example), and was not exposed to the plugin. Now that openedx-events signals exist, the signal can instead be imported from openedx-events, and regular django syntax can be used. In fact, the earlier mechanism of using apps.py should probably be deprecated, in favor of transitioning any necessary signals to an openedx-event.
I don't have a very good reason to explain why we went with the suggested way of listening to signals in plugins back then for the docs - this is the method I remember when I started experimenting with Django plugins. Even though the advantages of having a separate library to implement signals, we didn't question whether this should still be the recommended way after the library's implementation and consequent adoption. So, thank you for bringing this up!
Although I have a few concerns about deprecating this approach, which is mainly related to the fact that opened-events are not a drop-in replacement to Django signals in the edx-platform - so we still have a few of them to support. So, before deprecating it, we should offer a migration path for users of those signals.
As for the docs, a few months back I created this list of docs improvements to gradually implement this year. I added this one to it, so I plan to work on it in December or January at the latest.
Although I have a few concerns about deprecating this approach, which is mainly related to the fact that opened-events are not a drop-in replacement to Django signals in the edx-platform - so we still have a few of them to support. So, before deprecating it, we should offer a migration path for users of those signals.
@mariajgrimaldi: I believe this can be deprecated sooner-rather-than-later to avoid the contagion factor. That doesn't mean the feature will be removed until it is no longer needed. I think the "replacement" path for any legacy signal that is already in use in this way would be to introduce an openedx-event, which is a process that would take time, and could be tracked separately. Does this address your concern, or do you have other concerns? Thank you.
UPDATE:
... that opened-events are not a drop-in replacement to Django signals in the edx-platform
Note that we don't need a replacement of all signals, but just signals that are exposed publicly for consumption in a plugin. As far as I am aware, that is exactly what openedx-events is for, and these are the only type of events that should ultimately be consumed by plugins. I may be missing something though.
@robrap:
@mariajgrimaldi: Regarding the first point, its unclear whether you plan on reviewing my proposal? If we like it, we can land this change now, and not have to wait for your larger doc effort.
Or @kdmccormick, if you end up reviewing it.
@robrap: I'm sorry for not clarifying. I reviewed and approved the PR, so it's ready to merge. Thank you.
Proposed action items left for this ticket:
@robrap: confirmed! I'll take care of it on Monday. Thank you!
The how-to for receiving events documents two options (see https://github.com/openedx/openedx-events/blame/main/docs/how-tos/using-events.rst#L10-L53).
Please help me check my understanding. Is the following accurate?
I believe that the second option, using apps.py plugin configuration, pre-dates the use of openedx-events. In the earliest version of plugins, they needed to reach into a signal definition that was defined in edx-platform (as an example), and was not exposed to the plugin. Now that openedx-events signals exist, the signal can instead be imported from openedx-events, and regular django syntax can be used. In fact, the earlier mechanism of using apps.py should probably be deprecated, in favor of transitioning any necessary signals to an openedx-event.
Inside edx-platform, there are many uses of apps.py to listen to signals. See https://github.com/search?q=repo%3Aopenedx%2Fedx-platform+plugin_app&type=code. I find this very confusing, because it is using "plugin" syntax for non-plugin apps that live inside the repo. Is there any good reason to do this, or is this just a lot of copy/paste of something that doesn't make as much sense?
One proposal is to deprecate the apps.py plugin way of listening to signals. If the signal is an OpenedxSignal, then the warning could simply ask to refactor to use simple django syntax. Otherwise, the deprecation warning could note that the simple django syntax should be accessible for any signal inside the same repo, or if this is truly for a plugin, then a new signal should be added to openedx-events to expose the event.
Thoughts?