-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Fix copy plugins #3709
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
Fix copy plugins #3709
Conversation
|
@ojii @mkoistinen @evildmp @stefanfoulis @czpython Could you test this for possible regressions? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't those two lines redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id and pk are not directly related to each other after loading the model from the storage so we need to update both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Model.pk is a proxy to the primary key field: https://github.com/django/django/blob/89e2c60f4396241c667b7a1de37765b7c96d702f/django/db/models/base.py#L554
Updating id should also update pk (or vice versa)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
plugin_instance is a derived class, so pk points to cmsplugin_ptr_id (the derived class primary key) while id is the primary key of the parent class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then why are they both set to the same value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll shut up about this now. Seeing this just confused me as it doesn't feel right and I hoped that because you touched code near it maybe you'd have some insight as to what's going on.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this is required to return a functional / correct object with right values (plugin_instance is returned and is later used by other functions) without hitting the database again as Django ORM does not make this magic for us.
It's ugly? Yes, I think so.
We should investigate this further for 3.1? I totally agree
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love it when this happens... :-)
|
code looks good to me. don't have a real project to properly test this for regressions though. |
|
Was asked to look at this in #3637, I'm not clear on what bug this is solving but have no doubts there is a bug ;) Is there a ticket I'm missing that explains the details of this? As noted in #3637, the issue there is that plugin ordering is thoroughly screwed up on publish and that bug was introduced in the develop branch after the django-treebeard changes were merged. It doesn't appear that this PR addresses that issue. |
|
@jsma yeah, after checking your PR the issue is slightly different, nevermind: I though it could be caused by the leak, but it's not the case |
|
OK, I've tested this on an existing project with some pretty custom and deeply-nested plugin setups. Seems to work! Great job! |
the low level method
CMSPlugin.copy_pluginmesses up the reference to the old plugin changing it to the new oneThis has no consequence if the old plugin instance is not "reused", but it may affect lower level use (like in blueprint)