FlipperPA / wagtailcodeblock

StreamField code blocks for the Wagtail CMS with real-time PrismJS Syntax Highlighting.
BSD 3-Clause "New" or "Revised" License
156 stars 29 forks source link

Need some hints for wagtail 5 Compatibility #40

Closed wu-changxing closed 1 year ago

wu-changxing commented 1 year ago

Hi, Flipper,

First of all, I want to express my gratitude for your hard work on this project. I really appreciate the effort you've put into creating it. However, I've encountered an issue when trying to use it with Wagtail 5. While it works perfectly fine with Wagtail 4.2, it seems to break with Wagtail 5.

I've spent the last two days trying to debug and identify the problem, but unfortunately, I haven't been able to find a solution yet. I was wondering if you could provide me with some hints or guidance on how to fix it.

Here's what's currently happening: whenever I add a code block to the stream field, the entire stream field disappears. Additionally, I sometimes encounter the following error:

    self.full_clean()
project/macaw/venv/lib/python3.9/site-packages/django/forms/forms.py", line 433, in full_clean
    self._clean_fields()
/project/macaw/venv/lib/python3.9/site-packages/django/forms/forms.py", line 440, in _clean_fields
    value = bf.initial if field.disabled else bf.data
project/macaw/venv/lib/python3.9/site-packages/django/forms/boundfield.py", line 127, in data
    return self.form._widget_data_value(self.field.widget, self.html_name)
project/macaw/venv/lib/python3.9/site-packages/django/forms/forms.py", line 224, in _widget_data_value
    return widget.value_from_datadict(self.data, self.files, html_name)
/project/macaw/venv/lib/python3.9/site-packages/wagtail/blocks/base.py", line 579, in value_from_datadict
    return self.block_def.value_from_datadict(data, files, name)
/project/macaw/venv/lib/python3.9/site-packages/wagtail/blocks/stream_block.py", line 116, in value_from_datadict
    count = int(data["%s-count" % prefix])
project/macaw/venv/lib/python3.9/site-packages/django/utils/datastructures.py", line 86, in __getitem__
    raise MultiValueDictKeyError(key)
django.utils.datastructures.MultiValueDictKeyError: 'content-count'

Any help or suggestions you can provide would be greatly appreciated.

Thank you once again for your contributions and support.

thinkingcomputing commented 1 year ago

A fix would be greatly appreciated but I'm afraid I'm not sure where to begin with contributing. I had it available as part of a streamfield and the whole content section wouldn't show in the wagtail admin until I commented out codeblock as an option in the models. Happy to provide anything else you think is useful and sorry I can't be more help.

FlipperPA commented 1 year ago

Hey folks, I’ve been on holiday. I’m hoping to get time to look into this this week, as well as a few other issues.

FlipperPA commented 1 year ago

@thinkingcomputing @wu-changxing I've been unable to reproduce this behavior and have confirmed that Wagtail 5 works with wagtailcodeblock. From the latest changes pushed to main, here's what I did:

git@github.com:FlipperPA/wagtailcodeblock.git && cd wagtailcodeblock 
python3.11 -m venv venv && . venv/bin/activate
pip install -e .

pip freeze | grep wagtail yields this, as expected.

wagtail==5.0.2
-e git+ssh://git@github.com/FlipperPA/wagtailcodeblock.git@5bf6b11407f304cd147c9a9f260a82dee24ab32f#egg=wagtailcodeblock
image

Can you get the same error to appear with the included test app? Thanks!

thinkingcomputing commented 1 year ago

Apologies @FlipperPA but I didn't use your test app as requested in the message above. However, I did update my development version to your newly released 1.29.0.1 and it worked so I pushed it to production where it also works so it looks like you've fixed it thanks :)

FlipperPA commented 1 year ago

@thinkingcomputing Hooray! I'm glad it is working.

wu-changxing commented 1 year ago

After I merged the newest version, the problem solved! Thank you again!