Handle null text in first_paragraphs() #396
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
This link to a modpack on beta throws a 500: https://beta.spacedock.info/pack/1/some%20stuff
#385 made use of our
first_paragraphs()
function to get a short-ish text that can be put into tneog:description
tag for mod packs.However, the description column is nullable, and while it appears that new mod packs will always be initialized with an empty string, there can be old ones with NULL/None.
Pattern.split
can only take strings as argument, and thus throws for None.It would have been nice if mypy caught that, because
first_paragraphs(test: str)
explicitly asks for an argument that is notNone
, however as we already found out, it can't check Jinja templates. Additionally it seems to assume thatModList.description
cannot beNone
.Changes
first_paragraphs
now acceptsOptional[str]
and returns an empty string iftext
isNone
.This solution should be more future-proof than e.g. checking for
None
within the template before callingfirst_paragraph
, as it catches all occurrences.