Skip to content

Suppress separators for null fields in table formatters#7923

Open
foozleface wants to merge 1 commit intospecify:mainfrom
calacademy-research:fix-6406
Open

Suppress separators for null fields in table formatters#7923
foozleface wants to merge 1 commit intospecify:mainfrom
calacademy-research:fix-6406

Conversation

@foozleface
Copy link
Copy Markdown
Collaborator

Fixes #6406
Contributed by @foozleface

When an object formatter has fields with a sep attribute and the related record is NULL, the separator still renders (e.g. a stray " - " with no value after it). The root cause is that blank_nulls wrapping around the nested formatter result prevents concat(sep, expr) from seeing the NULL, so the separator is unconditionally emitted.

Implementation

  • In ObjectFormatter.objformat(), unwrap blank_nulls from the nested formatter result before assigning raw_expr, so that apply_stringish sees the raw expression and concat(sep, expr) correctly returns NULL when the nested formatter produced NULL. The outer blank_nulls still handles final display.
  • Added a regression test that creates two AccessionAgent records (one with and one without an Accession) and verifies the separator only appears when the related record exists.

Testing instructions

  • Create a formatter that references a relationship field with a sep attribute (e.g. AccessionAgent formatter with <field sep=" -Acc: " formatter="Accession">accession</field>)
  • Create records where the relationship is NULL
  • Verify the formatted output does not include the stray separator for NULL relationships
  • Run python manage.py test specifyweb.backend.stored_queries.tests.test_format.test_format_query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 📋Back Log

Development

Successfully merging this pull request may close these issues.

Table Formats with null formatted field breaks conditional separator behavior

1 participant