Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Custom serializer + list bug #44

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

Merged
merged 3 commits into from
Jun 21, 2022

Conversation

Kakebake
Copy link
Contributor

@Kakebake Kakebake commented Jun 20, 2022

What
This PR fixes a bug where the rendering of a node can fail if it has fields not supported by Block and follows directly after a list item.

The list item logic would pass in the first node after the list as context and cast it to a Block. This fails if the node has fields not supported by Block. Which is the case for custom serializer blocks.

The context is actually not used, and removing it solves the bug.

What used to not work?
A custom element right after a list of some kind.

What Screenshot Comment
Sanity Screenshot 2022-06-21 at 11 43 15 A custom element after a list
JSON Screenshot 2022-06-21 at 11 45 44 First item is a list, the second element is a custom element. signatures is what makes the code fail

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 20, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 1.16%.

Quality metrics Before After Change
Complexity 9.41 🙂 9.07 🙂 -0.34 👍
Method Length 53.67 ⭐ 50.70 ⭐ -2.97 👍
Working memory 7.99 🙂 7.85 🙂 -0.14 👍
Quality 64.90% 🙂 66.06% 🙂 1.16% 👍
Other metrics Before After Change
Lines 290 301 11
Changed files Quality Before Quality After Quality Change
portabletext_html/renderer.py 57.03% 🙂 57.10% 🙂 0.07% 👍
tests/test_rendering.py 97.70% ⭐ 97.32% ⭐ -0.38% 👎

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
portabletext_html/renderer.py PortableTextRenderer._normalize_list_tree 21 😞 215 ⛔ 10 😞 38.74% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
portabletext_html/renderer.py PortableTextRenderer._render_span 16 🙂 160 😞 11 😞 45.12% 😞 Try splitting into smaller methods. Extract out complex expressions
portabletext_html/renderer.py PortableTextRenderer._render_node 8 ⭐ 132 😞 9 🙂 59.14% 🙂 Try splitting into smaller methods
portabletext_html/renderer.py PortableTextRenderer.render 9 🙂 124 😞 9 🙂 59.16% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@Kakebake Kakebake force-pushed the espenra/custom-serializer-after-list-bug branch from e6949b0 to 69fa475 Compare June 20, 2022 14:20
…list

This commit fixes a bug where the rendering of a node can fail
if it has fields not supported by Block and follows directly after
a list item.

The list item logic would pass in the first node after the list as context
and cast it to a Block. This fails if the node has fields not supported
by Block. Which is the case for custom serializer blocks.

The context is actually not used, and removing it solves the bug.
@Kakebake Kakebake changed the title bugfix: fix a bug where custom serializer blocks can fail if after a … Custom serializer + list bug Jun 20, 2022
@Kakebake
Copy link
Contributor Author

I made the tests fail first so you can confirm the fix fixes the bug.

Copy link
Member

@rix1 rix1 left a comment

Choose a reason for hiding this comment

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

Took a look at this, but it's a bit hard for me to understand what the original problem was and how it behaves after the fix. Could you update the description and provide some examples on before/after? 😇

Copy link
Contributor

@sondrelg sondrelg left a comment

Choose a reason for hiding this comment

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

Have to admit my portable-text knowledge is getting a little rusty, so I'm not easily able to judge whether the JSON added is valid or not - but I trust you 🙂 The code change looks harmless as well, and seeing that all tests are green, I'm fairly sure this is fine to merge 👍

Thanks for adding the failing test first. Definitely makes it much easier to review.

@Kakebake
Copy link
Contributor Author

Kakebake commented Jun 21, 2022

Took a look at this, but it's a bit hard for me to understand what the original problem was and how it behaves after the fix. Could you update the description and provide some examples on before/after? 😇

Good point, it is quite hard to understand. Took me hours just to find what caused the bug 😅

I added some screenshots to at least explain the situation from a user perspective. Merging ang releasing the change.

@codecov-commenter
Copy link

Codecov Report

Merging #44 (8e895e3) into main (b79237f) will not change coverage.
The diff coverage is 100.0%.

@@          Coverage Diff          @@
##            main     #44   +/-   ##
=====================================
  Coverage   92.1%   92.1%           
=====================================
  Files          7       7           
  Lines        307     307           
  Branches      57      57           
=====================================
  Hits         283     283           
  Misses        13      13           
  Partials      11      11           
Impacted Files Coverage Δ
portabletext_html/renderer.py 93.2% <100.0%> (ø)

@Kakebake Kakebake merged commit ce9ecbb into main Jun 21, 2022
@Kakebake Kakebake deleted the espenra/custom-serializer-after-list-bug branch June 21, 2022 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.