-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug] Sortedm2m causes vpnclients to be destroyed and recreated every time the configuration or templates are changed #399
Comments
I thought that we could solve it in a different way:
|
I will start working on this and make a PR soon. |
But if we just skip, then how the ordering will be maintained 🤔 |
@devkapilbansal good question, but there's no concept of ordering in VPN clients, so template m2m relationships (config.templates) have to be deleted and recreated, because those one do have the concept of order, what we have to avoid being deleted and recreted are VpnClient instances, VpnClient is a custom m2m through model. So, templates through emit openwisp-controller/openwisp_controller/config/apps.py Lines 62 to 66 in 32c4bc9
The receiver function (actually a class method) is here: openwisp-controller/openwisp_controller/config/base/config.py Lines 207 to 241 in 32c4bc9
To anyone wanting to work on this: please write a test first, eg:
Please do not forget updating the docs, that is, we have to state clearly in the README that vpnclients relationships are not deleted when clearing templates because of how sortedm2m works to reorder templates. |
@nemesisdesign Very naive question - Which file should be ideally used for writing the test for this solution? |
@Saurav-Shrivastav take a look at https://github.com/openwisp/openwisp-controller/blob/master/openwisp_controller/config/tests/test_config.py#L297-L379. There's also one test which will have to be changed (the one which tests the |
…fixed openwisp#399 - Modified `manage_vpn_clients` callback method - vpnclients are not cleared on post_clear - for a post_add action, a new vpnclient is created only if it doesn't exist already - added a Test for the above functionality - modified 2 tests (viz - test_clear_vpnclients and test_automatically_created_cert_deleted_post_clear) to incorporate the new functionality Fixes openwisp#399
How to replicate:
Expected result:
The certificate created in the previous steps should still exists.
Actual result:
The certificate is destroyed and a new one is created.
Cause:
This is caused by the annoying implementation of django-sortedm2m, which implements the reodreding of m2m relationships by clearing templates and adding them back again, which causes signal receivers of openwisp to destroy and recreate many different things.
My thoughts:
I'm not sure if we can solve it without forking django-sortedm2m and implement the reordering in a different way, nor I'm sure if it's worth pursuing this now, but I want to leave this here for others to know so at least we can be aware of it.
The text was updated successfully, but these errors were encountered: