Skip to content
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

Removed an incorrect blocking of plugin cleanup on cancellation #537

Merged

Conversation

Aiky30
Copy link

@Aiky30 Aiky30 commented May 29, 2020

This PR aims to fix an issue where cancelling a new text plugin before it is ever saved leaves the page in a corrupt state due to models being created that are not cleaned up.

The JS uses a count of the structure mode items for positions which does not include any "ghost" cms_plugins which skews the number of plugins.

The following PR aimed to resolve this issue but it also contains other changes that were rightfully rejected due to using the wrong Jquery package: #515

The error that this PR fixes:
IntegrityError at /en/admin/cms/placeholder/add-plugin/ duplicate key value violates unique constraint "cms_cmsplugin_placeholder_id_language_position_bad60ebe_uniq" DETAIL: Key (placeholder_id, language, "position")=(9, en, 1) already exists.

@codecov-commenter
Copy link

codecov-commenter commented May 29, 2020

Codecov Report

Merging #537 into support/4.0.x will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@              Coverage Diff               @@
##           support/4.0.x     #537   +/-   ##
==============================================
  Coverage          66.66%   66.66%           
==============================================
  Files                 13       13           
  Lines                387      387           
  Branches              40       40           
==============================================
  Hits                 258      258           
  Misses               115      115           
  Partials              14       14           
Impacted Files Coverage Δ
djangocms_text_ckeditor/widgets.py 81.81% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8c13993...9dd8f3d. Read the comment docs.

@Aiky30
Copy link
Author

Aiky30 commented Jun 1, 2020

@vxsx Hi Vadim, This PR fixes an issue that is common and breaks being able to edit a page in the CMS for Django cms v4. An issue occurs because the new plugin architecture no longer uses treebeard and has it's own custom tree implementation, the cancel operation doesn't clean up when the user clicks cancel.

The steps to reproduce the issue:

  1. Create a new page and then proceed to edit it
  2. Create a text plugin but click cancel rather than letting it succeed
  3. Try to recreate the text plugin in the same placeholder again, this breaks and errors without this fix due to the fact that the cancel has not completely cleaned up the cms_plugin entry.

I can provide two sites for demo, one with the fix and one without, I can send these via the normal slack channels when you are ready to view, if of course you have the time to see the issue and then this fix in action. :-)

Copy link
Contributor

@vxsx vxsx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's alright, I get it. Before - we didn't "save" the plugin before finishing the edit, so cleanup of the plugin itself didn't need to happen, only of unsaved children, now it's different

"""
If any "ghost" plugins are left behind by a failed cancellation
the creation of a new plugin can be blocked by the fact that a new plugin is
trying to use the same position, to fix this we can clean any existing orphns

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor spelling mistake: orphns

trying to use the same position, to fix this we can clean any existing orphns
and recalculate the placeholder plugins positions
"""
has_ophans = False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this to orphans as well?

with transaction.atomic():
readd_response = self.client.get(endpoint)

# FIXME: Breaks because the code catches and integrity and then allows one to be thrown again!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this issue still exists can we fix it before merging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, it won't be going over until this test is fixed, it's blocking the pr.

@Aiky30 Aiky30 requested a review from vxsx June 8, 2020 17:14
@FinalAngel
Copy link
Member

@Aiky30 looks sane to me

@FinalAngel FinalAngel merged commit 1a16c43 into django-cms:support/4.0.x Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants