Suppress separators for null fields in table formatters#7923
Open
foozleface wants to merge 1 commit intospecify:mainfrom
Open
Suppress separators for null fields in table formatters#7923foozleface wants to merge 1 commit intospecify:mainfrom
foozleface wants to merge 1 commit intospecify:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #6406
Contributed by @foozleface
When an object formatter has fields with a
sepattribute and the related record is NULL, the separator still renders (e.g. a stray " - " with no value after it). The root cause is thatblank_nullswrapping around the nested formatter result preventsconcat(sep, expr)from seeing the NULL, so the separator is unconditionally emitted.Implementation
ObjectFormatter.objformat(), unwrapblank_nullsfrom the nested formatter result before assigningraw_expr, so thatapply_stringishsees the raw expression andconcat(sep, expr)correctly returns NULL when the nested formatter produced NULL. The outerblank_nullsstill handles final display.AccessionAgentrecords (one with and one without anAccession) and verifies the separator only appears when the related record exists.Testing instructions
sepattribute (e.g. AccessionAgent formatter with<field sep=" -Acc: " formatter="Accession">accession</field>)python manage.py test specifyweb.backend.stored_queries.tests.test_format.test_format_query